- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 08:24 AM
Hi Experts,
I am trying to set value on 'contact type' choice field on Request and RITM table. when user submits catalog item from service portal, the script should compare 'opened by' value and 'requested_for' value. if those values are same contact type should be set as 'self-service' else contact type should be as 'phone'.
How can I achieve this.?
Thanks,
Rocky.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 09:11 AM
Hi Rocky,
I see the code is not aligned as per the best practice i.e In an "after" Business Rule current.update() should also not be used. Any action that might be performed in an After Business Rule can usually have been added in a high ordered Before Business Rule, eliminating any need for an explicit update() function call. In addition, updating in an After Business Rule will cause all Before Business Rules to run again, which, as mentioned previously could cause performance processing issues.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0715782
Updated code below. Please make sure to give the order number highest in the BR that you have created.
var contactType = '';
if(current.opened_by == current.request.requested_for){
contactType = 'self-service';
}
else{
contactType = 'phone';
}
current.contact_type = contactType;
current.setWorkflow(false);
current.update();
// query request table and update for it as well
var req = new GlideRecord('sc_request');
req.get(current.request);
req.contact_type = contactType;
req.update();
- Pradeep Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 09:11 AM
Hi Rocky,
I see the code is not aligned as per the best practice i.e In an "after" Business Rule current.update() should also not be used. Any action that might be performed in an After Business Rule can usually have been added in a high ordered Before Business Rule, eliminating any need for an explicit update() function call. In addition, updating in an After Business Rule will cause all Before Business Rules to run again, which, as mentioned previously could cause performance processing issues.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0715782
Updated code below. Please make sure to give the order number highest in the BR that you have created.
var contactType = '';
if(current.opened_by == current.request.requested_for){
contactType = 'self-service';
}
else{
contactType = 'phone';
}
current.contact_type = contactType;
current.setWorkflow(false);
current.update();
// query request table and update for it as well
var req = new GlideRecord('sc_request');
req.get(current.request);
req.contact_type = contactType;
req.update();
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 10:06 AM
Hi Pradeep,
I am using the below script to populate requested for from catalog item to request.
BR: on sc_request_item table.
When: After - Insert
script:
var req = new GlideRecord('sc_request');
req.get(current.request);
req.requested_for = current.variables.u_requester;
req.update();
Now, I am trying to compare requested_for and opened_by to set contact type.
The script you and Ankur provided is setting contact type as "self-service" though requested for and opened by are different. I tried this on my personal instance too.
Any other input ?
Thanks,
Rocky.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 08:47 PM
Can you share Personal dev instance link ONLY?
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 11:20 AM
It worked, After I replaced "current.request.requested_for" with "current.variable.u_requester".
Thanks,
Rocky.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 11:34 AM
Thanks for the update Rocky.