- 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 08:27 AM
Hi Rocky,
if this is only 1 catalog item then you can use workflow run script activity if for all then use after insert BR on sc_req_item table
Just to inform requested_for is present at sc_request table so you need to dot walk to request record
1) Workflow approach
Run Script : I assume opened_by is populated on RITM
var contactType = '';
if(current.opened_by == current.request.requested_for){
contactType = 'self-service';
}
else{
contactType = 'phone';
}
current.contact_type = contactType;
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();
2) BR Approach: If this is required for all
Note: I assume opened_by is populated on RITM
BR: After Insert on sc_req_item
Script:
var contactType = '';
if(current.opened_by == current.request.requested_for){
contactType = 'self-service';
}
else{
contactType = 'phone';
}
current.contact_type = contactType;
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();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 08:57 AM
Hi Ankur,
I have tried this on BR. But, not working as expected. though opened by and requested for are different it is setting contact type as "self-service".
Thanks,
Rocky.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 09:05 AM
Hi Rocky,
the above BR should be after insert on sc_req_item table
Also I assume opened_by is populated on RITM table then only it would work
Is opened_by populated on your ritm record?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 09:11 AM
Yes Sir, opened_by is populated on both request and ritm records.
Thanks,
Rocky.