- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 09:01 PM
Here's a BR I have on the sc_task table where it has a GlideRecord to check the current record's Request State on the sc_request table. I want 'request_state' CHANGES TO 'closed_complete' instead of equals, how can I achieve this?
var reqGR = new GlideRecord('sc_request');
reqGR.addQuery('sys_id', current.request);
reqGR.query();
if (reqGR.next()) {
// Check if the sc_request conditions are met
if (reqGR.request_state == 'closed_complete' && reqGR.short_description == ABC123') {
gs.eventQueue('sn_customerservice.ape_rc_modify',current,current.variable_pool.user_email,gs.getUserName());
gs.info('FPIM email recipient' + current.variable_pool.user_email);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 09:15 PM
Hi @HP8 ,
You can't check if the state changes to "Closed Complete" or not in a GlideRecord Query.
If you want to trigger some event when the Request is closed, then write the BR in the Request table with the condition: State Changes to Closed Complete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 10:47 PM - edited 11-07-2024 10:48 PM
Hello @HP8
Yes, in ServiceNow, you can use changesTo() to check if a field has changed to a specific value.
For example:
if (current.state.changesTo('Closed')) {
// Logic for when the state changes to 'Closed'
}
In this case, current.state.changesTo('Closed') will return true only if the state field has just changed to Closed. This is useful for triggering logic when a field reaches a particular value.
In ServiceNow, there are several functions you can use to track changes in fields. Here’s a quick rundown:
changesFrom(value): Checks if a field changed from a specific value.
- Example: current.state.changesFrom('Resolved') returns true if the state was previously Resolved and has now changed to something else.
changesTo(value): Checks if a field changed to a specific value.
- Example: current.state.changesTo('Closed') returns true if the state has just changed to Closed.
changes(): Checks if a field’s value has changed at all, regardless of its previous or current value.
- Example: current.state.changes() returns true if there’s any change in the state field.
Each of these functions is helpful for monitoring specific field changes in your scripts, especially in business rules or other server-side scripts where tracking state transitions is essential.
"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar