use current.varable_name and previous.variable_name functionality in a workflow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 02:03 PM
I am scripting within a workflow and am trying to trigger an action based on if a boolean field value has changed. Since workflow activities do not have the built in "change" condition like a business rule, I am attempting to do this with a condition. In an "IF" workflow activity, I have " if (current.variable_name == true && previous.variable_name == false) {run script} ". The function is not able to enter this statement, because it does not recognize the use of current.variable_name or previous.variable_name. Can I use these key words in a workflow script?
Any insight appreciated!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 06:34 PM
Hi Katie,
Did you try the condition builder to see if 'changes' criteria is already exists? I don't think, previous object is defined on workflow context, since the workflow is instantiated later or on a condition. You can implement your requirement in a BR and the desired workflow can be triggered for the BR.
Darshak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 06:40 PM
Check out the API for variables using Xplore.
You can get the appropriate object as follows:
var gVariable = current.variables.variable_name.getGlideObject()
Then, to get the previous value you can do this:
gVariable.previousValue
I haven't tested this code in practice, as it's not documented, but it just might work!
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 12:40 PM
The condition builder does not have "changes" as an option for Workflow scripts. I believe I have only seen this as a built-in condition option on Business Rules. I think I will have to go with a BR for simplicity sake to get the functionality I am looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 06:40 PM
Hi Katie,
You must try as current.variables.variable_name. This is the syntax. Also I doubt that you can not use 'previous' in the Workflow. Please have a look at this wiki LINK.
I hope this helps. Please mark correct/helpful based on impact