- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 07:37 AM
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.
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!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 07:44 AM
Hi,
The sys_id in the state flow is referencing a specific state flow definition.
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 09:58 AM
Hi,
The API reference is all found on developer.servicenow.com.
Click Developers (on the left)
Then a menu choice on the top left says API. Take your pick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 10:41 AM
Thanks!
I'm guessing in my original question, "current" was a record/instance of Request. Where do I find that in the API? I see mostly Glide-whatever stuff.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 10:47 AM
Current refers to the record you are working on with it's current values. It is most often a GlideRecord instance (e.g. an incident record or a user record.) The object is available in many server side scripts (business rules, UI actions, workflow scripts, etc.)
Server side scripting fundamentals
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 09:52 PM
Hi Chuck,
Hope you can help me.
i used scripts in "4.1 Defining the Trigger" Displaying a Custom Dialog - ServiceNow Wiki
When i reopen a hr case , add comment and save , it's changing the state from Resolved to "work in progress" and saving the comment from pop up box in the description field. However, when i impersonate an end user and tried to reopen a case, its just updating the comment but not changing the state to work in progress. Is it due to my admin access?
When i add "new StateFlow().processFlow(current, 'c77bfec04f682200143327201310c7d7', 'manual'); " to client script, above " g_form.setValue("state", '18');", its not doing anything , not even updating the input comment into description field.
Is there any way to use this script "new StateFlow().processFlow(current, 'c77bfec04f682200143327201310c7d7', " 'manual'); in client script?
in the client script :-
function validateComments() {
//This script is called when the user clicks "OK" in the dialog window
//Make sure there are comments to submit
var comments = gel("dialog_comments").value;
comments = trim(comments);
if (comments == "") {
//If comments are empty, alert the user and stop submission
alert("Please enter your comments before submitting.");
return false;
}
//If there are comments, close the dialog window and submit them
GlideDialogWindow.get().destroy(); //Close the dialog window
g_form.setValue("description", comments); //Set the "description" field with comments in the dialog
g_form.setValue("state", '18');
g_form.save();
}