- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 05-18-2018 11:03 AM
This if for those out there starting with javascript on the ServiceNow platform possibly solving a hard problem with a simple script.
Background:
We have the incident table and the table called service_offering.
Service_offering have a true/false field called “Global service”. The incident form have a field called “Global support” which is also true/false. Service Offering is a reference field on the Incident form.
If we have a Service Offering that has the flag “Global service” then if we choose that Service Offering on the incident form the flag “Global support” is set to true.
And if the flag on Service Offering is false then it will set to false on Incident aswell.
- • Navigate to Business Rules
- • Create new: “Set Global support = True”
- • Table: Incident
- • When to run: Before
- • Insert: True
- • Update: true
- • Filter conditions: Service offering – changes
- • Actions: Leave empty
- • Advanced: True
- • Condition: leave blank
Script:
(function executeRule(current, previous /*null when async*/) {
if(current.service_offering.u_global_service == true){
current.u_global_support = true;
}
else {
current.u_global_support = false;
}
})(current, previous);
Explanation:
- Since we always have a record of service_offering loaded we do not need to use Gliderecord to query it. Remember that Service Offering is a reference field on the incident form.
- We dot walk through service_offering to the field u_global_service which is the flag we want to check.
- If it is true then we set u_global_support to true aswell via the current command.
- If it is not true (else) then set it to false.
Hope this simple guide will aid our new generation ServiceNow developers!
Regards, Glenn Eriksson
- 11,547 Views