It's all about the answers!

Ask a question

Javascript Validator Check


Peterson dos Santos (44139) | asked Jan 23, 5:59 p.m.
Hi Friends,

I would like to know if is there a way to check if a work item is new using javascript validators

I really appreciate any help:
Regards

Accepted answer


permanent link
Davyd Norris (2.7k217) | answered Jan 24, 5:55 p.m.
If a work item is brand new - ie. unsaved, then the workitem's state will be null, otherwise it will be a string representing the ID of one of the states you've defined in your workflow.

The following code snippet will check whether the work item is brand new and exit the validator

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("com.ibm.team.workitem.api.common.Status");
...
  const WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
  const Status = com.ibm.team.workitem.api.common.Status;

        const wiState = workItem.getValue(WorkItemAttributes.STATE);
        if (wiState === null) {
          return Status.OK_STATUS;
        }
       
Peterson dos Santos selected this answer as the correct answer

One other answer



permanent link
Ralph Schoon (63.5k33646) | answered Jan 24, 2:35 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 Validators can access the current workflow state of a work item using workItem.getValue(WorkItemAttributes.STATE)




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.