Making Attribute as a mandatory using workitems action in RTC
We are now using Rational Team Concert 4.0.1 version (Windows Platform). we want to make one field (Attribute) as a mandatory field based on action name (while selecting action in workitem).
So please let me know the function OR code details for making the attribute as mandatory.
Note: We can make fields as mandatory based on state name using “Required Attributes” precondition in operation behavior but we want to make some mandatory fields based on action name.
Accepted answer
Now the same script is working fine in my environment. I found 2 issues and resolved them.
1. There was an empty script which was showing errors in the console log. I removed it from Links.
2. Old script was picked from links because i was using the same name for .js file.
When I resolved above issues, script is working perfectly fine. The attribute is turned on as mandatory attribute and work item is not saved, if the attribute is empty.
Thanks for the links and help.
5 other answers
Use:
since 4.0 M1getWorkflowAction()
returns a string that is the id of a workflow action currently selected by the user. This action will be executed when the item is saved. If the user has not selected any action this method will returnnull
. Note: This method works only when used inside a Condition script, the return value will always benull
when this is used in other customization script types.
with the
Required Attributes For Condition
Precondition/Advisor
Thanks for your support!!.
As mentioned, I have created below dojo script to make a attribute as mandatory based on action but it is not working. Could you please help on this?.
FYI,
dojo.provide("SQLQualityStatus");
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
(function() {
dojo.declare("SQLQualityStatus", null, {
getValue: function(attribute, workItem, configuration) {
var SQLQuality = getWorkflowAction();
if(SQLQuality === "ChangeRequestWorkFlow.action.a113") { // ChangeRequestWorkFlow.action.a113 == action ID
return true;
}
return false;
}
});
})();
Thanks,
Rajiv
Comments
I would suggest to carefully read the https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript again to figure out where to get the workflow action. It is a method on the configuration data.
dojo.provide("com.ibm.team.workitem.rejectbydesign");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.ibm.team.workitem.rejectbydesign", null, {
getValue: function(attributeId, workItem, configuration) {
var action= configuration.getWorkflowAction();
if ( action === "projectstatustracking.action.a30" ) {
// action is reject by design
return true;
}
return false;
}
});
})();
Comments
Debug your script. See https://jazz.net/library/article/1360
You can also print to the logs. See https://jazz.net/library/article/1093 Lab 5
Not sure if === as opposed to == could be a problem.
I even tried with == but no luck
Hello Ralph,
Thanks for the links. I debugged my script using above article.
I found an error in the condition script. I rectified it.
Now, it shows a mandatory field sign for the attribute, if the given workflow is selected. But after that, even if that mandatory field is null, it saves the WI. It does not give any error and moves to next state.
Did you configure the operation behavior (pre-condition) that is mentioned in https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Conditions and the Enactment Workshop?
I am using RTC Version 5.0.1 and the pre-condition enabled is "Required Attributes for Condition"
Using the console log, I see that as soon as I click on save on the work item, the getWorkflowAction() is changed and the attribute becomes non-mandatory.
Is there any issue in 5.0.1?
Here is the script
dojo.provide("com.ibm.team.workitem.rejectbydesign");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.ibm.team.workitem.rejectbydesign", null, {
// getValue: function(attributeId, workItem, configuration) {
matches: function(workItem, configuration) {
var act= configuration.getWorkflowAction();
console.log(" action is = " +act);
if (act === "projectstatustracking.action.a30" ) {
// action is reject by design
console.log(" action is reject by design---true");
return true;
}
console.log(" action is reject by design----false");
return false;
}
});
})();