Revert to New UI action is not working

raj99918
Tera Contributor

Hi,

 

I have requirement like When I click on Revert to New menu it should ask for work notes to be mandatory and after filling the work notes and after saving it state remains the same and after again clicking the 2nd time revert to new menu and filling the work notes 2nd time and saving it then the state changing to New. How can I achieve it in the first click after filling the work notes and save it. Below is my script.

 

 

revertToNew(current);
action.setRedirectURL(current);

 

function revertTonew(changeReq) {
var change = new ChangeRequest(changeReq);
if (current.work_notes == '') {
gs.addErrorMessage('Worknotes Mandatory');

}
else if (!change.revertToNew())
gs.addErrorMessage(gs.getMessage('State Model for {0} changes does not allow reverting change from {1} state', [change.getValue('type'), change.getDisplayValue('state')]));


}

 

 

4 REPLIES 4

raj99918
Tera Contributor

@Ankur Bawiskar Inputs please

Ankur Bawiskar
Tera Patron
Tera Patron

@raj99918 

how will you know user clicked 1st time and 2nd time?

Unless you store the click count on some custom integer field you cannot track it

1) create custom integer field and update it with 1 when 1st time it gets clicked

2) in UI action script check if the field value is 1 if yes it means it's clicked 2nd time and now set state to other value

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Its not about the count when we click the Revert to New from menu and asking for worknotes to fill and after filling and save it needs to set to New state but its not happening from the above UI action can you please check whether I need any changes in it  

@raj99918 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader