Business Rule script to populate a reference field from a string field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2019 10:27 PM
Hi all
I have a String field "u_wrnumber" that is populated from the email body using a business rule
i need to populate a Reference field "Parent" from the u_wonumber fiild and have tried the following script in a business rule that is not working
These are the two fields on the form
current.parent=current.u_wrnumber;
i can manually put the WR Number in the Parent field as it exists in the task table
could anyone please assist with how i populate the parent field
Thankyou
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2019 10:52 PM
Hi Kev,
So you are sure that value exists in the table which is referred by Parent; then try this; also that value should be display value
current.setDisplayValue('parent',current.u_wrnumber);
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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
05-15-2019 11:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2019 12:33 AM
Hi Kev,
Just remove line number 4 and keep only line 5 and try once
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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
05-15-2019 11:24 PM
Hi Kev,
Your script is not working as Reference Field takes sys_id and not value.
Moreover, as the BR will run before Insert or Update and parent is a mandatory field, it should cause an error during form submission
As an alternative You could use an onChange Client Script for the WR Number Field:
var gr = new GlideRecord('parent field table name');
gr.addQuery('name of field',g_form.getValue('u_wrnumber'));
gr.query();
if(gr.next())
g_form.setValue('parent',gr.sys_id);
For your current solution remove
current.parent=current.u_wrnumber; and only keep the second line of the code.