How to change the value of Stage field in Requested Item using Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 06:48 AM
Hello everyone,
I want to update the stage of Requested Item record based on the state value of Catalog Task.
I have one workflow on the Catalog Task and it will be in Wait condition using Wait for condition activity, when there is any state change in Catalog Task it will change the state and stage of associated Requested Item using below script
var grItem = new GlideRecord('sc_req_item');
if (current.state == 3) {
if (grItem.get(current.request_item)) {
grItem.state = 3;
grItem.stage = 'Completed';
grItem.update();
}
answer = true;
}
else if (current.state == 4) {
if (grItem.get(current.request_item)) {
grItem.state = 4;
grItem.stage = 'Request Cancelled';
grItem.update();
}
answer = true;
}
else if (current.state == 7) {
if (grItem.get(current.request_item)) {
grItem.state = 7;
grItem.stage = 'Request Cancelled';
grItem.update();
}
answer = true;
}
else {
answer = false;
}
By this script, it can able to change the Stage field value in Form View of Requested Item as shown in below screenshot
The list view of this Requested Item is as show in below screenshot
But I want to mark the stage as Completed when the stage is changed by the workflow activity script as mentioned above.
I can able to change the value of Stage field but it only reflects on Form View not in List View.
Thanks in advance,
Smit Ladani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 08:24 AM
Can you post the workflow you are having trouble with (and what table is the WF running on)? Also, where is the script you posted? Is it in a Run Script activity in the WF mentioned in the previous question or a Business Rule on the sc_task table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 09:57 PM
Hi Ryan,
Main workflow is running on Requested Item table so when the user create the request that workflow will get triggers and then approval will approve the request and task will be created. When the task is created it will trigger following below workflow because this workflow is running on Catalog Task.
Now as you can see there is Wait for condition in that I have written the script which I have posted in question.
Thanks in advance,
Smit Ladani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2020 05:01 AM
I'm not sure I understand why there is a separate workflow just for a wait for condition for the task. You should be able to accomplish this within the RITM workflow. On the Catalog task activity in the sc_req_item based workflow, check this box:
Likewise, for the task routing based on the state of the task, if you right-click the catalog task activity header you can "Add Conditions" to have it route in different directions based on the state of the task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2020 03:35 AM
Ok got it!!
And I had second workflow because it is requirement and need to execute only once when the state is Closed Complete, Closed Incomplete or Closed Skipped. So implemented other workflow.