Set owner script - graceful way to not execute?
I have successfully built a script that sets the Owned by attribute based on the value selected in an enumeration. I then wanted to have it also check a boolean attribute and if that boolean is false, to NOT set the Owned by field, but to let the user set it. I have this working, but not gracefully.
Below is a snippet of the code. For the "else" condition I am simply returning an empty string instead of a UUID. This has the intended effect - the Owned by attribute is not set automatically, but it of course results in a null pointer exception. I was wondering if there was a better way to accomplish this so as not to throw an error?
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
var SetECMOwner= dojo.declare("org.example.SetECMOwner", null, {
getValue: function(attributeId, workItem, configuration) {
// retrieve state of auto-assign attribute
var autoAssign = workItem.getValue("delegateflag");
// if auto-assign is turned on (by default), execute the body of the script
if (autoAssign == true ) {
DO SOME STUFF;
return UUID
}
else {
return "";
}
Below is a snippet of the code. For the "else" condition I am simply returning an empty string instead of a UUID. This has the intended effect - the Owned by attribute is not set automatically, but it of course results in a null pointer exception. I was wondering if there was a better way to accomplish this so as not to throw an error?
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
var SetECMOwner= dojo.declare("org.example.SetECMOwner", null, {
getValue: function(attributeId, workItem, configuration) {
// retrieve state of auto-assign attribute
var autoAssign = workItem.getValue("delegateflag");
// if auto-assign is turned on (by default), execute the body of the script
if (autoAssign == true ) {
DO SOME STUFF;
return UUID
}
else {
return "";
}
One answer
Hi,
I might be missing something but why not simply return the unassigned value for your OwnedBy field (usually "unassigned")? Would that have undesired side effects for your use case?
- Arne
I might be missing something but why not simply return the unassigned value for your OwnedBy field (usually "unassigned")? Would that have undesired side effects for your use case?
- Arne
Comments
Thanks for the input. Unassigned is not the desired end result, but rather whatever owner the user selects. After thinking about it some more seems the answer is:
workItem.getValue(WorkItemAttributes.OWNER);
So basically setting owner to whatever owner is set to - the value the user specified.