It's all about the answers!

Ask a question

Attribute customization - How to prioritize calling the calculated script before Operation behavior on save


Shwetha G (60231) | asked Dec 20 '16, 11:01 a.m.
edited Dec 20 '16, 11:07 a.m.
 Hi All,

I need to  call the calculated script before Operation behavior on save. 

This is the current scenario [Was able to achieve steps 1 to 5, but not able to succeed through steps 6 and 7] : Could you please help me on this. 

1. Defined an attribute say.."LinkCounter" of type integer

2. Added a calculated script that contains the Oslc URI to get the count of "links" for the current WI (It usually returns the count of number of WI linked to it...eg ...0(zero) for no links present, 1 for one link present etc)

3. On a particular state...say "Set Done" state, I have a "operation behavior" set as "required for type and attribute" for this attribute "LinkCounter".

4. Then on changing through different states, when I am about to set it to "Set Done State" It check for the LinkCounter value. Since there is no link for the current WI, It will be the default value "0 zero".

5. As the operation behavior is set, It doesn't allow me to save the WI  [error message : Attribute"LinkCounter" not set ]

This is the main area to be highlighted :
6. I now link some WI to this current WI. So that count of the attribute would become 1.
7. But the calculated script is not dynamically called and 1 is not getting updated on click of save button.

 I am getting the error message : Attribute"LinkCounter" not set 

Is there any way, I can call the calculated script before the opeartion behavior is set on the attribute ? so that when I create links to the WI, it calls the script and value is updated and then the operation behavior is called.

Thanks in advance

2 answers



permanent link
Lily Wang (4.9k714) | answered Dec 21 '16, 7:29 p.m.
According to the document https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Calculated_values :

 If you configure a Script-based calculated value, the script will be executed in three cases:

  • When a work item is created, the script is executed
  • When a work item is saved, the script is executed to recalculate the value.
  • When an attribute which the current attribute depends on is changed, the value of the current attribute is recalculated. Depending on the presentations of the two attributes this may not work in all cases.
To trigger the script before saving the work item, you can set the attribute depend on another change attribute such as Status. 

Comments
Shwetha G commented Dec 21 '16, 11:27 p.m.

Hi Lily,

Thanks for your reply. You are correct, script is executed only on those conditions.

but my situation is : Due to operational behavior, the "LinkCounter" attribute is becoming mandatory field on "set done" state, And am getting the error message : "Attribute LinkCounter should be set".

Note :
LinkCounter value can be set only by script(script calculates the total links present) and not manual entry of value.

Now am linking one WI to the current WI so that, count becomes 1. and when I save the WI, Save is not allowed, due to the error message : "attribute LinkCounter is not set".

But value of "LinkCounter" can be populated only on save of the WI, as its value is populated from the script.(i.e, When WI is saved, number of links is now updated to 1 in RTC) and the value will populate to the attribute.

So Is there any way, I can prioritize on save then on Operation behavior "required on types and attributes".

Thanks in advance.



1
Lily Wang commented Dec 22 '16, 1:01 a.m.

The problem is when you add a link to the current WI, the calculated value provider script will not be triggered so it still remains as "0". Then when you try to save the WI, the pre-condition fails.

The possible solutions are:
- as Donald suggested, use a follow-up action. After adding a link, save the current WI to make the follow-up action update the LinkCounter. Then change the WI status to "Set Done" and save it again.
- otherwise, you can add a dependency between LinkCounter and WI State to make the value provider triggered before saving WI. In this case, you still need to add link first and change WI state after that.


Shwetha G commented Dec 22 '16, 1:57 a.m. | edited Dec 22 '16, 3:10 a.m.

Really really thanks for your reply Lily.

Yes I completely agree to your point that, the script is not called when the link is added and it still remains "0".

As Donald suggested, I have the follow-up action set up.

The following scenario is perfectly working fine,it is my basic scenario(User will add the link, before "set done" state). That adding a link, calling the follow-up script to update the link count and change the status to "Set done". It is populating the correct link counts.

But my scenario is the reverse : (In short : User should not be allowed to set the WI to "set Done" state, when there is no links present for the WI) :

1. User selects the "set done" state.
2. Gets the error message : "Attribute LinkCounter not set"  [ as am making this value mandate - in operation behavior on set done state]. LinkCounter internally has the scripts that count the link value.
3. User links the some WI to current WI.
4. On click of save, RTC is not allowing to save the links attached and script is not called, being value not updated and finally error message not going.

5. It is expecting value to the "LinkCounter" field, that I cant enter manually, which need to be populated from the script.

Is there any way, first saving and then calling the operation behavior(that overrides it)

I look forward for your suggestions and comments.


Shwetha G commented Dec 22 '16, 2:55 a.m.

Really really thanks for your reply Lily.

Yes I completely agree to your point that, the script is not called when the link is added and it still remains "0".

As Donald suggested, I have the follow-up action set up.

The following scenario is perfectly working fine,it is my basic scenario(User will add the link, before "set done" state). That adding a link, calling the follow-up script to update the link count and change the status to "Set done". It is populating the correct link counts.

But my scenario is the reverse : (In short : User should not be allowed to set the WI to "set Done" state, when there is no links present for the WI) :


Shwetha G commented Dec 22 '16, 2:58 a.m. | edited Dec 22 '16, 3:00 a.m.

Really really thanks for your reply Lily.

Yes I completely agree to your point that, the script is not called when the link is added and it still remains "0".

As Donald suggested, I have the follow-up action set up.

The following scenario is perfectly working fine,it is my basic scenario(User will add the link, before "set done" state). That adding a link, calling the follow-up script to update the link count and change the status to "Set done". It is populating the correct link counts.

But my scenario is the reverse : (In short : User should not be allowed to set the WI to "set Done" state, when there is no links present for the WI) :


Shwetha G commented Dec 22 '16, 3:00 a.m.
  1. User selects the "set done" state.
  2. Gets the error message : "Attribute LinkCounter not set"  [ as am making this value mandate - in operation behavior on set done state]. LinkCounter internally has the scripts that count the link value.
    3. User links the some WI to current WI.
    4. On click of save, RTC is not allowing to save the links attached and script is not called, being value not updated and finally error message not going.

    5. It is expecting value to the "LinkCounter" field, that I cant enter manually, which need to be populated from the script.

    Is there any way, first saving and then calling the operation behavior(that overrides it)

    I look forward for your suggestions and comments.

Donald Nong commented Dec 22 '16, 3:15 a.m.

You cannot expect a detailed implementation from the forum. Have you added the attribute "LinkCounter" in the WI editor, as hidden? If it's not there, I'm not sure the calculated value script will ever run.

showing 5 of 7 show 2 more comments

permanent link
Donald Nong (14.5k414) | answered Dec 21 '16, 8:38 p.m.
You have two issues to deal with here.
1. Attribute"LinkCounter" not set - to avoid this, you should use a "default value" provider. It is reasonable to set it to 0 as when the work item is created, usually there should be no links attached to it.
2. Automatically change "LInkCounter" value when a bi-directional link is added outside of the work item. I am pretty sure in this case the calculated value script will _not_ be called (for the target work item). You may have to develop a follow-up participant in the source work item to change the "LinkCounter" value directly, say +1. But if the source is from QM or RM, I am not aware of any means to do it automatically. Additionally, you may also need to consider the situation where a link is _removed_.

Comments
Shwetha G commented Dec 21 '16, 11:41 p.m.

Hello Donald,

Thanks for your reply, I would like to add my contents to the issues you have mentioned.

1. Attribute"LinkCounter" not set - I agree for your comment, that there will be no links present when a WI is created, However, I have declared the WI as Integer, and the value zero is present in the beginning.

Attribute is not set only when
saving the value to the attribute as it is mandatory field now and its value cant be set manually. It has to be only  through script.

2. You may have to develop a follow-up participant in the source work item to change the "LinkCounter" value directly, say +1.

Could you please help me with more details on the follow-up participant as to what it is ? am not sure about it.

The source for this is RTC itself.

I look forward for your comments and suggestions.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.