How do I write UI action script which changes the state of a Request?

lightblu
Mega Expert

Hi all,

I would like some documentation/help regarding ServiceNow StateFlow scripts. The script below is executing on the "Ready for Work" UI action for a default Request. It is changing the state from Approved (13) to Ready(10). I do not understand how the script changes the state from Approved (13) to Ready (10): It seems to me like the 32 character GUID/sys_id is one for an instance of the Ready (10) state, but I have no idea how to tell that it is for the Ready (10) state.

find_real_file.png

I ultimately would like to write the script for a custom UI action which changes the current state to a new state, exactly like the UI action above is doing. But I have no idea how to specify how to specify the right GUID for the new state.

Thanks!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi,



The sys_id in the state flow is referencing a specific state flow definition.



State Flows - ServiceNow Wiki



If you want to write your own UI action, de-activate this one and use the condition field to say "When would I like this to appear on the form" and the script to say "What would I like to do when the user clicks it". If you want it to appear when the state is 10 and change the state to 13, it would look as simple as this:



Condition: current.state == '10'


Script:


current.state = 13;


current.update();


action.setRedirectURL(current); // stay on this form



UI Actions - ServiceNow Wiki


View solution in original post

8 REPLIES 8

Chuck Tomasi
Tera Patron

Hi,



The sys_id in the state flow is referencing a specific state flow definition.



State Flows - ServiceNow Wiki



If you want to write your own UI action, de-activate this one and use the condition field to say "When would I like this to appear on the form" and the script to say "What would I like to do when the user clicks it". If you want it to appear when the state is 10 and change the state to 13, it would look as simple as this:



Condition: current.state == '10'


Script:


current.state = 13;


current.update();


action.setRedirectURL(current); // stay on this form



UI Actions - ServiceNow Wiki


Hey Chuck,



That worked - thanks!



I would like to know where all the documentation for this kind of scripting (UI actions and stuff) is so I can figure these things out myself in the future. I've been browsing the wiki but seems hard to find.


Hi,



If you want some self-tutorial/training information, go to developer.servicenow.com and get started. I also recommend signing up for one or more of our training sessions beginning with System Administration.



Training and Certification | IT Systems Management | ServiceNow


Hi Chuck,



I would just like some API documentation for scripting. For example, an API that tells me all the methods for a Request record (.update(), .state(), etc.). I'm not really interested in official training/courses. Just some API docs would be nice. Thanks for all your help!