- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 01:16 AM
Hi
I want to add the number field of a record (if it exists) into a field in another table. Is it best to run a business rule, or to specify this in the dictionary entry for the reference field? Then next questions is, how do I do this?
All help is highly appreciated š
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 01:21 AM
Best way is to use Business Rule only if you want to achieve it when any Changes or Update happened in your record.
And if you want to achieve it for existing record, you should go with Fix Script.
So based on your requirement you can implement by GlideRecord() another table and update the field.
NOTE: For Reference field, sys_id is stored in the backend.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 01:21 AM
Best way is to use Business Rule only if you want to achieve it when any Changes or Update happened in your record.
And if you want to achieve it for existing record, you should go with Fix Script.
So based on your requirement you can implement by GlideRecord() another table and update the field.
NOTE: For Reference field, sys_id is stored in the backend.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 01:29 AM
ok, thanks for your reply @AnubhavRitolia
can't get the br to work with the current settings:
table: sn_customerservice_case
when: before insert and update
conditions: u_request is empty
script:
(function executeRule(current, previous /*null when async*/) {
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 02:16 AM
Please find the updated BR below:
table: sn_customerservice_case
when: After insert and update
conditions: u_request is empty
(function executeRule(current, previous /*null when async*/) {
var req = new GlideRecord('sc_request');
req.addQuery('parent', current.sys_id); //or try 'parent.sys_id' if 'parent' does not work.
req.query();
if(req.next())
{
current.u_request = req.sys_id;
current.update();
}
})(current, previous);
What I understand from your code is that When record in created on 'sn_customerservice_case' table and Request field is empty, you search for Request whose parent is that Customer Service Case. Than map that Request to your Custom Request field on Case table.
As BR is already on 'sn_customerservice_case' table, no need to query it again in script. Also as already you are checking for parent of Request so why to again update that field.
Please try above solution if my understanding was right.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-20-2022 03:47 AM
Thank you very much @AnubhavRitolia
Somehow this don't seem to work for me..I tried both parent and parent.sys_id in the add query. It looks very correct to me, but I suspect it is something in the "Customer service request integration" blocking me from doing this. But that is just a general assumption