SCTASK Fields to Update a Record on a ServiceNow Table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello everyone, I am currently developing a catalog item containing these 5 SCTASKs. The requestor specified what will each SCTASK will contain which are fields that differ from the other per SCTASK. Every SCTASK contains different fields.
They also requested that this fifth or final SCTASK will have to update a target record on a ServiceNow table when the state was changed to Closed Complete.
I would like to kindly seek everyone's recommendations and expert judgement as to how to execute or configure this, if ever this is possible.
Thank you in advance.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
STEP 1: Create the Catalog Item
Navigate to:
Service Catalog
→ Catalog Definitions
→ Maintain Items
→ New
Create:
Name:
Follow-up Fulfillment Request
STEP 2: Create Variables
Open the Catalog Item.
Go to:
Variables
→ New
Variable 1
Update Target Record
Question: Target Record
Type: Reference
Name: target_record
Table: Incident //your table name
STEP 3: Create Other Catalog Variables
Example:
Business Justification
Requested By
Comments
STEP 4: Publish Catalog Item
Test:
Open Catalog
↓
Submit Request
↓
Ensure Target Record is captured
Navigate:
Flow Designer
→ New Flow
Follow-up Fulfillment FlowCatalog Item RequestedSave.
STEP 5: Create SCTASK 1
Add Action:
Create Catalog TaskShort Description:
Infrastructure Validation
Assignment Group:
Infrastructure
STEP 6: Create SCTASK 2
Add:
Create Catalog TaskShort Description:
Security Review
STEP 7: Create SCTASK 3
Example:
Application VerificationSTEP 8: Create SCTASK 4
Example:
Compliance ApprovalSTEP 9: Create SCTASK 5
Example:
Final Fulfillment Review
STEP 10: Create Event Registry
Navigate:
System Policy
→ Events
→ Registry
Name:
ritm.all.tasks.completed
STEP 11: Create Business Rule
Navigate:
System Definition
→ Business Rules
→ New
Name
Check All Tasks CompleteTable
sc_taskAfterChecked
Filter Condition
State changes to Closed CompleteSTEP 12: Business Rule Script
Paste:
(function executeRule(current, previous) {
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.request_item);
taskGR.addQuery('state', '!=', 3); // Closed Complete
taskGR.query();
if (!taskGR.hasNext()) {
gs.eventQueue(
'ritm.all.tasks.completed',
current,
current.request_item.toString(),
''
);
}
})(current, previous);
What Does This Do?
Example:
Task 1 closes → Open tasks exist → Stop
Task 2 closes → Open tasks exist → Stop
Task 3 closes → Open tasks exist → Stop
Task 4 closes → Open tasks exist → Stop
Task 5 closes → No open tasks → Raise Event
STEP 13: Create Script Action
Navigate:
System Policy
→ Events
→ Script Actions
→ New
Name
Update Selected Recordritm.all.tasks.completedSTEP 14: Script Action Logic
If Target Record is Incident only:
Use:
(function runAction(current, event) {
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(event.parm1)) {
var incidentSysId =
ritm.variables.target_record;
if (incidentSysId) {
var inc = new GlideRecord('incident');
if (inc.get(incidentSysId)) {
inc.work_notes =
'All fulfillment tasks completed.';
inc.state = 6; // Resolved
inc.update();
}
}
}
})(current, event);
STEP 15: Prevent Duplicate Updates
Create a field on RITM:
u_record_updated
(Boolean)
FalseBefore raising event:
if (current.request_item.u_record_updated)
return;
After updating target record:
ritm.u_record_updated = true;
ritm.update();
STEP 16: Testing
Test the following:
Test 1
Submit Catalog Item.
Verify:
5 SCTASKs created.Close Tasks 1–4.
Expected:
Target record NOT updated.Close final task.
Expected:
Selected target record updated.Modify closed tasks.
Expected:
Target record NOT updated again.Select different records.
Example:
INC0010005
INC0010010
PRB0000020
Correct record updated every time.Final Architecture
Catalog Item
↓
Target Record Variable
↓
Flow Designer
(Create 5 SCTASKs)
↓
Users Complete Tasks
↓
Business Rule (sc_task)
↓
Are all SCTASKs complete?
↓ No → Stop
↓ Yes
Raise Event
↓
Script Action
↓
Read Target Record Variable
↓
Update Selected Record
↓
Mark RITM as Processed
I have kept everything according to your requirements, but the table are according to testing purposes I have selected within the ServiceNow environment so that I can elaborate easily. So now just replace your table names according to your ongoing requirement and boom your problem is solved.
If you find this solution helpful please accept it as your answer and do mark as helpful as well. Thanks!