Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Calculated value execution cases

From my understanding, a calculate value script will be executed in 3 cases:
  • When a work item is created
  • When a work item is saved
  • When an attribute which the current attribute depends on is changed
Is there te possibility to check which case is executing the script?

I would like to have different behavior depending on the various cases.

Thanks in advance.
Bye.

0 votes


Accepted answer

Permanent link
I don't believe the third case happens unless the middle case is true.
I don't think the calculation happens in real time as the value is changed from what I remember, but then I'm not sure you would want a different case for the real time vs the save - what the value ends up being on the screen should be what is saved.

You can catch the creation case pretty easily by checking the State attribute - if the work item has just been created then workItem.getValue(WorkItemAttributes.STATE) === null

EDIT: I just checked and you are correct - the calculation is done in the client in real time. This means you can differentiate between the second case and the third by checking where the calculation was triggered. The real time case is done in the client, and the Save case is done on the server, so you can check for the window Object. If it's defined then you're in the client, if not then you're on the server
Angelo Corna selected this answer as the correct answer

0 votes


2 other answers

Permanent link
Hi Davyd, thanks for your response.

Consider this use case (it's not my really use case but it's ok for an example)

We have 3 fields
  • FieldA (Small String, ReadOnly)
  • FieldB (Small String)
  • Action (Enumeration)
When Action field value is Modify I want that the value of FieldA is copied on FieldB.
After this I can change the value of FieldB and I can save the WorkItem. After the save FieldA must contains the original value and FieldB must contains the new one.

In order to copy the value of FieldA to FieldB, I've create a simple calculated value on FieldB with Action dependency  and it works without problems, when Action field is set to Modify the value of FieldA is copied on FieldB and I can change the FieldB value.

Unfortunately, when I save the WorkItem, the calculated vale runs again and overrides the new value inserted on FieldB.

So, if I'm able to understand how the calculated value script is fired (for Action field change or for save Workitem) I'm able to correctly manage this use case on JavaScript.

Thanks. Bye.



0 votes

Comments

So, in that case, check for the existence of the window Object - that only exists when you're in the client. If it exists then do the copy, if not then don't.

How can I check it?

/***********
Licensed Materials - Property of IBM
(c) Copyright IBM Corporation 2011. All Rights Reserved.

Note to U.S. Government Users Restricted Rights: 
Use, duplication or disclosure restricted by GSA ADP Schedule
Contract with IBM Corp.
***********
/
dojo.provide("com.example.ValueProvider.checkLocation");

(function() {
    dojo.declare("com.example.ValueProvider.checkLocation", null, {

        getValue: function(attribute, workItem, configuration) {
  return window ? "client" : "server";
        }
    });
})();

    getValue: function(attribute, workItem, configuration) {
      console.log('here');
      if (workItem.getValue(WorkItemAttributes.STATE) === null) {
        return 'created';
      }
      if (window) {
        return 'modified';
      }
      return 'saved';

    }

I just checked this and the server side save never fires - I can edit the calculated value and it just saves it


Permanent link

The API is explained here: https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Calculated_values 


I am not aware of an official mechanism that would reveal why the calculated value is run.

I am aware, that users have looked into the API, especially in the browser. There are more functions and objects available in the browser. Some users have used them, even if they are not documented. This can work, but might break in the future. Please be aware, that those objects and methods might not be accessible in the Eclipse client environment.

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,926

Question asked: Jun 21, 5:44 p.m.

Question was seen: 756 times

Last updated: Jun 24, 9:32 p.m.

Confirmation Cancel Confirm