- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 05:15 AM
Hi All,
The query is, I need to restrict to add affected CIs to the change request if the change state is not in implement/review/cancelled/closed.
I have written the below script but the script is not working, the script is not entering into second if loop.
(function executeRule(current, previous /*null when async*/ ) {
var taskRef = current.task.getRefRecord();
var tableName = taskRef.getTableName();
var state = taskRef.state;
gs.info('Table Name: ' + '-->' + tableName);
if (tableName === 'change_request' || tableName === 'change_task') {
if (state === 500 || state === 600 || state === 900 || state === 1000) {
gs.info("Enter into second IF loop");
gs.addErrorMessage('The Change request is in ' + taskRef.state + " " + ', So cannot add affected CI');
current.setAbortAction(true);
}
return;
}
})(current, previous);
Thanks & Regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 06:37 AM
Glad to know.
Please close the thread by marking appropriate response as correct so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 05:18 AM
script looks fine.
Did you check the state value is correct in comparison?
What's your debugging analysis?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 05:20 AM
I check the choices in sys_choice table, and choices are looked good.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 05:25 AM
BR is on which table and what type?
it should be on task_ci table and before insert
Did it go inside the 2nd IF?
what came in the table name and state value?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 05:22 AM - edited 12-27-2024 05:45 AM
update as this, the choice values for states you are using are wrong
(function executeRule(current, previous /*null when async*/ ) {
var taskRef = current.task.getRefRecord();
var tableName = taskRef.getTableName();
var state = taskRef.state;
gs.info('Table Name: ' + '-->' + tableName);
// stateIN - 1, 0, 4
if (tableName == 'change_request' && (state == -1 || state == 0 || state == 4)) {
gs.info("Enter into second IF loop");
gs.addErrorMessage('The Change request is in ' + taskRef.state + " " + ', So cannot add affected CI');
current.setAbortAction(true);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader