Calling a javascript function (dojo/ajax) when an RTC work item is saved in a certain state

I am trying to do some customization to an RTC work item. When I move the work item to a certain state, and save it, I need to be able to invoke a java service running on a different machine through HTTP. So, first question is how do I set things up to call a custom javascript when I save the RTC work item in a certain state. I am assuming I can use dojo methods within the javascript function that I call.
2 answers

Hello Tim,
pls refer to https://jazz.net/library/article/1003/#calc-values
then check https://jazz.net/library/article/1093
especially https://jazz.net/wiki/pub/Main/ProcessEnactmentWorkshop/20121122_ScriptBasedCustomization_Lab5_Solutions_Scripts.zip
where you'll find WorkFlowStateScriptedCalculatedValueProvider.js
which seems to correspond to your request:
(...)
var workFlowState = workItem.getValue(WorkItemAttributes.STATE);
debug("WorkflowState: " + workFlowState);
// Adjust attachment numbers in the code below
if(workFlowState=="") return "{{https://clm.example.com:9443/ccm/service/com.ibm.team.workitem.common.internal.rest.IAttachmentRestService/itemName/com.ibm.team.workitem.Attachment/1|New}}";
if(workFlowState=="tecReviewWorkflow.state.s1") return "{{https://clm.example.com:9443/ccm/service/com.ibm.team.workitem.common.internal.rest.IAttachmentRestService/itemName/com.ibm.team.workitem.Attachment/2|Proposed}}";
(...)
Hope it helps,
Eric
Comments

Eric, you can not detect a state change that way. You can only detect the state you are in. So if a state change should trigger this, see below.
The only way to detect the state changes in JavaScript the community was able to come up with is like this.
- Add a hidden attribute and an attribute customization that depends on the state. If the state value of the hidden attribute is different from the state you read, write the new value to the hidden attribute.
-
The other customizations trigger on the hidden attribute. Each time that changes they act.

I am not sure you can do this with attribute customization https://jazz.net/wiki/bin/view/Main/AttributeCustomization as the API seems to be quite limited. You would also have to use a hidden attribute to detect the state change. Howewer, I don't claim to be an expert.
The HTTP filtered value provider could be an option to access data on a server. See http://jorgediazblog.wordpress.com/2012/06/27/work-item-customization-httpconector-and-oauth-in-rtc-4-0-for-oslc/ for an example. https://jazz.net/library/article/1093 also shows some basics about attribute customization in Lab 5.
I also found https://jazz.net/forum/questions/84143/question-on-calling-a-service-from-rtc-webui which might be relevant in your case. I am however not sure this works in the context of JavaScript.
I assume you could also use the Chrome or Firefox debug mode to find out what JavaScript can be called in a script.
The HTTP filtered value provider could be an option to access data on a server. See http://jorgediazblog.wordpress.com/2012/06/27/work-item-customization-httpconector-and-oauth-in-rtc-4-0-for-oslc/ for an example. https://jazz.net/library/article/1093 also shows some basics about attribute customization in Lab 5.
I also found https://jazz.net/forum/questions/84143/question-on-calling-a-service-from-rtc-webui which might be relevant in your case. I am however not sure this works in the context of JavaScript.
I assume you could also use the Chrome or Firefox debug mode to find out what JavaScript can be called in a script.
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Sep 26 '14, 3:05 a.m.The question is also, what is the call supposed to achieve. Do you want to automatically set a calculated attribute?