- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 08:54 AM
Can anyone help me in getting this as need to auto change status of Change Request form depends on Catalog Task status in servicenow
as off now when RITM is created then Catalog Task and Change Request are getting created via workflow.
@Ankur Bawiskar @Anil Lande @Sumalatha Y @BharathChintala @mattystern @priyasunku @asifnoor @Pradeep Sharma @SatyakiBose
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 12:45 PM
Hi,
Configure flow as below to update change status.
Thanks & Mark Answer Correct/Hit Thumbs Up. If my inputs help you to achieve what you are looking.
Sumalatha Y
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 02:44 AM
you need to decide which state value to set here -2 or -1
try this updated script
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("change_request");
gr.addQuery("parent", current.request_item);
gr.query();
if (gr.next()) {
if(current.state == '2')
{
gr.state = '-2 || -1'; //choice Value For Scheduled or Implement
gs.info('sample enter 1');
}
else if (current.state == '3')
{
gr.state = '3'; //Choice Value for Closed
gs.info('sample 2');
}else if(current.state == '4')
{
gr.state = '4'; //Choice value for Cancelled
gs.info('sample 3');
}else if(current.state == '1')
{
gr.state = '-5'; //Choice value for open
gs.info('sample 4');
}
gr.update();
}
})(current, previous);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 01:58 AM
you have to add {} for all the loops where it has more than 2 lines. Also you are adding it in wrong way please check below code.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("change_request");
gr.addQuery("parent", current.request_item);
gr.query();
if (gr.next()) {
if(current.state == '2')
{
gr.state = '-2'; //choice Value For Scheduled or Implement
gs.info('sample 1');
}else if (current.state == '3')
{
gr.state = '3'; //Choice Value for Closed
gs.info('sample 2');
}else if(current.state == '4')
{
gr.state = ''; //Choice value for Cancelled
gs.info('sample 3');
}else if(current.state == '1')
gr.state = '-5'; //Choice value for open
gr.update();
}
})(current, previous);
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 02:22 AM - edited 03-13-2023 02:23 AM
nothing is working as when the Catalog Task state changes to "Work in Progress" the the Changes Request state is changing to "Scheduled" after that when the Catalog Task State value changes to "Closed Complete" the the Change Request state value is changing to "Canceled"
Task Table Values of State Field:
Change Request Table Values of State Field:
Business Rule which had written
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("change_request");
gr.addQuery("parent", current.request_item);
gr.query();
if (gr.next()) {
if(current.state == '2')
gr.state = '-2 || -1'; //choice Value For Scheduled or Implement
gs.info('sample enter 1');
}else if (current.state == '3')
{gr.state = '3'; //Choice Value for Closed
gs.info('sample enter 2');
}else if(current.state == '4')
{gr.state = ''; //Choice value for Cancelled
gs.info('sample enter 3');
}else if(current.state == '1')
gr.state = '-5'; //Choice value for open
gr.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 02:26 AM
@Arjun Reddy Yer you are not using loop open and closures properly. please check this and try to correct this code .please take sometime and work on the code because mistake is just on opening and close of {}.
if(current.state == '2')
{
gr.state = '-2 || -1'; //choice Value For Scheduled or Implement
gs.info('sample enter 1');
}
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 02:37 AM
Tried with below script but still unable to find
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("change_request");
gr.addQuery("parent", current.request_item);
gr.query();
if (gr.next()) {
if(current.state == '2')
{
gr.state = '-2 || -1'; //choice Value For Scheduled or Implement
gs.info('sample enter 1');
}
}else if (current.state == '3')
{
gr.state = '3'; //Choice Value for Closed
gs.info('sample 2');
}else if(current.state == '4')
{
gr.state = '4'; //Choice value for Cancelled
gs.info('sample 3');
}else if(current.state == '1')
{
gr.state = '-5'; //Choice value for open
gs.info('sample 4');
}
gr.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 02:44 AM
you need to decide which state value to set here -2 or -1
try this updated script
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("change_request");
gr.addQuery("parent", current.request_item);
gr.query();
if (gr.next()) {
if(current.state == '2')
{
gr.state = '-2 || -1'; //choice Value For Scheduled or Implement
gs.info('sample enter 1');
}
else if (current.state == '3')
{
gr.state = '3'; //Choice Value for Closed
gs.info('sample 2');
}else if(current.state == '4')
{
gr.state = '4'; //Choice value for Cancelled
gs.info('sample 3');
}else if(current.state == '1')
{
gr.state = '-5'; //Choice value for open
gs.info('sample 4');
}
gr.update();
}
})(current, previous);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
