How to utilize custom work item fields for Attribute Customization scripts?
I'm trying to write a script for a new condition under the Attribute Customization sub category. I found a a couple of basic js guides but wasn't able to find too much on working with custom work item fields. My goal is to write something that will only allow users to save a work item if certain conditions are met (work item has to be a certain type + a few custom fields have to have certain values). However, I'm unsure how to access these values since I wasn't able to find information on the necessary API.
Here's what I have currently:
(function() {var doDebug = true;var scriptname = "SaveCondition";var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;dojo.declare("com.ibm.tap.SaveCondition", null, {
matches: function(workItem, configuration) {debug("Start");//Get the work item typevar type = workItem.getValue(workItemAttributes.TYPE);//get the work item categories//var category = workItem.getValue(com.ibm.team.workitem.attribute.categoryconsole.log(type);//Get the value of the work item's category//var category = workItem.getValue(WorkItemAtrributreturn (type === "workitem") && (field1 === "x") && (field2 === "y");}
});})();
One answer
use the attributes ID
var data = workItem.getValue('attribute_id');
var data = workItem.getValue('attribute_id');
Comments
Thanks, Sam! I got the value of the fields I wanted to satisfy the above conditions. However, is there anyway to specify that the above conditions should only hold for a certain user role? I'm thinking about creating a separate user role that will only give partial access to certain work items. I.e. Users with this new role will only be able to set the attribute values and save the work item. They won't be able to manually transition it.
far as I know all the javascript customization scripts fire for all workitems with those attributes defined for all users in all roles.