It's all about the answers!

Ask a question

Calculated value script not returning the value.


Shwetha G (60331) | asked Dec 06 '16, 4:40 a.m.
edited Dec 06 '16, 5:31 a.m. by Ralph Schoon (63.4k33646)
Hi,

I have this dojo script, when i am jst trying to return a hardcoded value 35. but am not able to get the value to the attribute.

here the attribute is : Tracks of type integer. I always get the default value filled as zero.


dojo.provide("com.example.trackLink.formal");
(function() {

dojo.declare("com.example.trackLink.formal", null, {

        getValue: function(attribute, workItem, configuration) {
      
return 35;
}
    });
})();


Could you please help me this.
Thanks in advance.

Accepted answer


permanent link
Ralph Schoon (63.4k33646) | answered Dec 08 '16, 4:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Dec 08 '16, 4:29 a.m.
 You want to carefully read the documentation I sent you and understand the different types of attribute customization scripts and what you can access and what you can't.

Some more hints here:

https://jazz.net/library/article/1003
https://jazz.net/wiki/bin/view/Main/AttributeCustomization
https://rsjazz.wordpress.com/2016/07/15/rtc-process-customization-what-you-can-and-cannot-do/

You can not easily determine a state change in an attribute customization and you can not access links either. In order to do things like that you have to create a Java work item save advisor like https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/
Ralph Schoon selected this answer as the correct answer

Comments
Ralph Schoon commented Apr 17 '18, 8:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Some additional things:

Attribute customization execution rules are described in https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Calculated_values in the customization types. section.

You can not compute on load page.

You can not trigger on state change. I have seen some work around where users stored the state in hidden attributes. Please don't.

Read the limitations in the API in the link above. You have no real access to complex data or links. The best you can get for complex items is a Label or other representation.

2 other answers



permanent link
Miguel Tomico (5001423) | answered Dec 06 '16, 5:32 a.m.
edited Dec 06 '16, 5:47 a.m.

Your script works fine.

Go to the Attribute definition and make sure that:

- The attribute type is Integer

- You have selected the script in the 'Calculated Value' column.


Comments
Shwetha G commented Dec 07 '16, 11:13 a.m. | edited Sep 04 '17, 3:03 p.m.
 Thanks a lot for your replies Miguel Tomico and Ralph Schoon

@Miguel Tomico, I had set the attribute's type to integer and also set the calculated script, but still it didnt work.

Today i tried with parsing the integer then the value was returned.

@Ralph Schoon, thanks for sharing the links, this is very helpful for me as a beginner.

I still need your help :

I have a problem definition :

Whenever I set a WorkItem(say Problem), to "Set done" state, there should be a calculated script that checks whether the problem is having a "Tracks" Link associated. If not present, then it should not allow the user to close the problem. (In short : Every Problem should have a defect associated with it, before closing it)

Are there any solutions for this ?

Currently I am trying out this steps:

1. have a hidden field in the Problem.
2. Have a calculated script that contains a oslc uri, that hits the RTC server and fetches all the "tracks " WI, it will return a xml containing all the WI along with count of how many WI linked.
3. In the calculated script, I will use a regular expression to get the counts of linked items returned. If it return zero
then no WI linked to that problem, so that value should be passed to the hidden field.
4. when the user is selecting the "set done" state, it should check this hidden field value, if it is set to 1 then it should allow the user to "set done" else restrict.

Is this the correct approach, else please suggest me the better approach to access the "Links" of a WI.


I am struck with this following steps :( could you please help me with this.

1. Is there any way I can access the links to a particulr workItem eg... "Contributes to", "Tracks" etc..from dojo ?
2. Can I use REST/OSLC URIs in DOJO to check the "Links" of a WI.


Thanks in advance.




Shwetha G commented Dec 07 '16, 11:13 a.m.

 @Ralph Schoon, thanks for sharing the links, this is very helpful for me as a beginner.


Shwetha G commented Dec 07 '16, 11:15 a.m.

 I also need your support for my following queries.. Please help me :)


I have posted it below

Thanks in advance



permanent link
Ralph Schoon (63.4k33646) | answered Dec 06 '16, 5:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
 You might want to look into this workshop: https://jazz.net/library/article/1093 especially https://jazz.net/library/content/articles/clm/2012/process-enactment-workshop/workbook/pew-rtc-lab-workbook.pdf . We have not done an example for an int but I would suggest to read it anyway. Also  http://www.w3schools.com/ is a good first reference.

I'd try

var result = parseInt("35");
return result.

Comments
Shwetha G commented Dec 07 '16, 11:39 p.m.

Hello  Ralph,

I tried using above mentioned code, but no luck...however when i tried to add the dependency to the attribute, on changing the value of other attribute, this value is getting populated.

Is there any way that i can populate the value "35" on page load ? ITs only working when I have a dependency attribute value entered.

I have also set the Enable Process Attachment Scripts to true.

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.