SCTASK Fields to Update a Record on a ServiceNow Table

JerickA
Tera Contributor

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.

5 REPLIES 5

Priyaranjan181
Tera Expert

 

STEP 1: Create the Catalog Item

Navigate to:

Service Catalog
→ Catalog Definitions
→ Maintain Items
→ New

Create:

Name:
Follow-up Fulfillment Request
Submit.
 

STEP 2: Create Variables

Open the Catalog Item.

Go to:

Variables
→ New
Create:

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
Whatever business requires.

 

STEP 4: Publish Catalog Item

Test:

Open Catalog

Submit Request

Ensure Target Record is captured
 
STEP 5: Create Flow Designer Flow

Navigate:

Flow Designer
→ New Flow
Name:
Follow-up Fulfillment Flow
Trigger:
Catalog Item Requested
Choose your Catalog Item.

Save.

 

STEP 5: Create SCTASK 1

Add Action:

Create Catalog Task
Example:
Short Description:
Infrastructure Validation

Assignment Group:
Infrastructure
Save Task Output.

 

STEP 6: Create SCTASK 2

Add:

Create Catalog Task
Example:
Short Description:
Security Review
Save.
 

STEP 7: Create SCTASK 3

Example:

Application Verification
 

STEP 8: Create SCTASK 4

Example:

Compliance Approval
 

STEP 9: Create SCTASK 5

Example:

Final Fulfillment Review
Activate Flow.
 

 

STEP 10: Create Event Registry

Navigate:

System Policy
→ Events
→ Registry
Create:
Name:
ritm.all.tasks.completed
Save.

 

STEP 11: Create Business Rule

Navigate:

System Definition
→ Business Rules
→ New
Configure:

Name

Check All Tasks Complete

Table

sc_task
When
After
Update

Checked

 

Filter Condition

State changes to Closed Complete
Save.
 

STEP 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
Configure:

Name

Update Selected Record
Event Name
ritm.all.tasks.completed
Save.

STEP 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)
Default:
False
Modify Business Rule:

Before raising event:

if (current.request_item.u_record_updated)
return;
Script Action:

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.
Test 2

Close Tasks 1–4.

Expected:

Target record NOT updated.
Test 3

Close final task.

Expected:

Selected target record updated.
Test 4

Modify closed tasks.

Expected:

Target record NOT updated again.
Test 5

Select different records.

Example:

INC0010005
INC0010010
PRB0000020
Expected:
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!