Auto populate multiple reference fields on Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2018 05:15 AM
Hello
I have an issue with the auto-populating the fiends on the Record Producer form.
I have a table which has some fields, in this particular case I am interested in fields:
1) Role Number
2) Role Name
3) Role ERD
4) Role Type
This is how the record producer form looks like this:
When I choose any record in the Role Number field the rest of the three fields (Role name, ERD and Type) should be auto-populated. Please bear in mind that all of those 4 fields are reference fields which points to the same table.
My issue is that the only one fields which are Role ERD are auto-populated by the script and the rest is empty.
Can anyone have an idea why is this not working? BTW if I change the variable type to single line text it works just fine.
My Catalog Client script looks like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var value = g_form.getReference('role_number',callBack);
function callBack(value) { //reference is passed into callback as first arguments
g_form.setValue('role_erd', value.u_erd_number);
g_form.setValue('role_type', value.u_role_type);
g_form.setValue('role_name', value.u_sensitivity_description);
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2018 05:23 AM
Hi Michal,
Are those 3 fields reference?
role_erd, role_type and role_name
Also when you fetch value from the callback is it coming as sys_id since you are saying those 3 fields are reference it would require sys_id to set the value
Can you add alert statement there for those 3 values?
One thing you can try is: make the callback function outside
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var value = g_form.getReference('role_number',callBack);
}
function callBack(value) { //reference is passed into callback as first arguments
g_form.setValue('role_erd', value.u_erd_number);
g_form.setValue('role_type', value.u_role_type);
g_form.setValue('role_name', value.u_sensitivity_description);
}
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
12-04-2018 05:32 AM
Hi Ankur
What I mean as a reference, I want to say that role_erd, role_type and role_name are variable which are type reference. On the source table the u_erd_number, u_role_type, u_sensitivity_description are simple string values.
Here is the value for the alert:
123123, Business Process Role, Sensitivity description
Which by the way are correct data which I set up in the source table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2019 09:54 PM
Hi,
Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader