It's all about the answers!

Ask a question

Set user name automatically in “Owned by” field while changing the status of workitem in RTC


Rajiv Gandhi (34712) | asked Jan 18 '16, 7:55 a.m.

Dears,

 

We are planning to set user name automatically in “Owned by” field while changing the status of specific workitem(Change Request) in RTC. So I have created the below “calculated values” script to set RTC user name automatically in “Owned by” field but it is not working for me.  Could you please correct me on this script? and let us know the right script for my requirement. Thanks in advance!

 

FYI,

 

 

dojo.provide("DefaultOwner");

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); // To access the work item attributes

dojo.require("com.ibm.team.workitem.api.common.Status"); // To create a status object to return

dojo.require("com.ibm.team.workitem.api.common.Severity"); // To create a severity for the status

 

(function() {

 

 

 

    dojo.declare("DefaultOwner", null, {

 

        getValue: function(attributeId, workItem, configuration) {

                var state = workItem.getValue(com.ibm.team.workitem.api.common.WorkItemAttributes.STATE);

                //  var ManagerName = workItem.setValue(Rajiv Gandhi);

               //   var SetName = "Rajiv Gandhi";

 

var ManagerName = workItem.setOwner("Rajiv Gandhi");

      if((workItem.getValue(com.ibm.team.workitem.api.common.WorkItemAttributes.TYPE)=="change_request") && (state == "ChangeRequestWorkFlow.state.s45")){

                return ManagerName;

                }

    }

  });

})();

 

 

Thanks,

Rajivgandhi

Accepted answer


permanent link
sam detweiler (12.5k6195201) | answered Jan 18 '16, 8:03 a.m.
edited Jan 18 '16, 8:07 a.m.
the Owner field contains an object reference, not a string.

somehow you have to lookup the object from the users name string.
I haven't done this.. the javascript functions are limited in what they can do.

see this https://jazz.net/wiki/bin/view/Main/AttributeCustomizationExamples#Get_an_item_s_UUID_users_iterati
Rajiv Gandhi selected this answer as the correct answer

Comments
Ralph Schoon commented Jan 18 '16, 8:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Also note, that your calculation has to ALWAYS return a value. It is a function, a function has to always return a value to be syntactically correct. So you have to return the current value, if you don't want to change it.

This is  a popular question for attribute customization and has been answered many times already, JavaScript is very limited.  Carefully look into

 Lab 5 - in the beginning a lot of the limitations are explained.
I think it would be better to create a follow up action. That would have a lot more API access as well and could e.g. find the manager by role, which a JavaScript calculated value can't.


Rajiv Gandhi commented Jan 18 '16, 3:47 p.m.

Hi Ralph, Thanks for the valuable information.

4 other answers



permanent link
Rajiv Gandhi (34712) | answered Feb 18 '16, 2:16 a.m.

I have followed the below steps from wiki page as mentioned  Sam and Ralph. Now my requirement is working fine. Thanks Sam and Ralph for the valuable information.


Automatically set the value of an attribute based on state

Scenario: You need to automatically set the value of a work item attribute (e.g. Owner) when it is in a particular state (e.g. Verified)

Solution: Use a calculated value customization

  1. Note: The presented solution is experimental and should be used with caution:
    • This technique may not work with all attribute types.
    • The behavior of the Eclipse UI and the Web UI differs.
      • When using Eclipse, the value of an attribute is updated as soon as an item is saved.
      • In the Web UI, the value of an attribute stored on the server is updated as soon as an item is saved. However the value visible on screen is not updated in that case. If you need to see the new value you should refresh the web page. Note that the data on the server contains the correct value and this is just a UI issue.
    • It is recommended to combine this method with Owner must be a predefined user to assure data integrity.
  2. Create a new script-based calculated value provider. In the following we set the Owned By attribute of an item to a specific user when the item is in a particular state.
    dojo.provide("org.example.CalculatedOwner");
    
    dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
    
    (function() {
    var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
    
    var CalculatedOwner= dojo.declare("org.example.CalculatedOwner", null, {
    
        getValue: function(attributeId, workItem, configuration) {
            if (workItem.getValue(WorkItemAttributes.TYPE) === "defect" && workItem.getValue(WorkItemAttributes.STATE) === "4") {
                return configuration.getChild("parameters").getStringDefault("owner", "");
            } else {
                return workItem.getValue(WorkItemAttributes.OWNER);
            }
        }
    });
    })();
    		
    Note that you must always return a value that will be assigned to the Owned By field. In case the item is in the Verified state (index 4) we use a value that is configured in the project specification. Otherwise we use the current value of the Owned By field.
  3. This script requires a configuration entry in the process specification:
    <valueProvider id="calculatedowner" name="Calculated owner" providerId="com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider">
        <script class="org.example.CalculatedOwner" path="/workitem/scripts/common/CalculatedOwner.js"/>
        <parameters owner="_r4ct4I2vEeCCZ-jvhw8VFA" />
    </valueProvider>
    		
    The owner attribute defines which user needs to be set as owner. To get the user id for a particular user see Get an item's UUID.
  4. Finally assign this customization to the Owned By attribute in Work Items > Types and Attributes. Make sure to add dependencies on the Type and Status attributes since these are required for the calculation to work properly.
  5. This customization will allow any user to be selected as the owner of a defect as long as the defect is not in the Verified state. Once the defect is put into the Verified state the system will automatically set the owner of the item to the predefined user in the process specification.


permanent link
sayli Boralkar (157) | answered Mar 04 '17, 7:57 a.m.
how to get Workflow state ID?

 in your program u mentioned
 workItem.getValue(WorkItemAttributes.STATE) === "4"

how to know ids of custom workflow state or default workflow state?

Comments
Ralph Schoon commented Mar 04 '17, 10:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Accessing_an_item_s_Status_attri the state ID's can be found in the process configuration source and some historical information is mentioned in the documentation.


Ralph Schoon commented Mar 06 '17, 2:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Debugging or console.log are obviously always an option as well.


permanent link
deepti harinkhede (219) | answered Nov 21 '17, 1:55 p.m.
edited Nov 21 '17, 1:58 p.m.

Hi,

This solution is working for me. How can I set the owner for multiple workitem types through single script? for eg.

if (workItem.getValue(WorkItemAttributes.TYPE) === "defect") {
return configuration.getChild("parameters").getStringDefault("owner", "owner should be the scrum master");
} else if (workItem.getValue(WorkItemAttributes.TYPE) === "task") {
return configuration.getChild("parameters").getStringDefault("owner", "owner should be team member");
} else if (workItem.getValue(WorkItemAttributes.TYPE) === "story") {
return configuration.getChild("parameters").getStringDefault("owner", "owner should be project lead");
}
else {
return workItem.getValue(WorkItemAttributes.OWNER); }


permanent link
AMEYA KALE (176) | answered Feb 04 '20, 9:38 a.m.

 Can some one please tell the accurate place to put <ValueProvider> tag in process config?

I tried but getting the  Unsupported value - _wgiM4O5SEem3D5FEFVFywQ in logs. Need some assistance.


Comments
Ralph Schoon commented Feb 04 '20, 10:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
It puts itself in there, if you configure one. Use a test environment to play around with it. Then look into the process configuration.


Also please ask your own questions and do not comment questions in other users questions answers.

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.