- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 04:48 AM
Hello Experts,
I have a requirement to auto populate values from user table to catalog item form based on selected user name.
I have written below onchange client script so whenever primary account name is selected it auto populates value from user table.
But employee type is not populating. Employee type field is choice field on user table
below is the onchange client script which fails to populate the employee type.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var caller = g_form.getReference('var_primary_acc_name', doAlert); // doAlert is our callback function
}
function doAlert(caller) { //reference is passed into callback as first arguments
g_form.setValue('var_name', caller.name);
g_form.setValue('var_employee_type', caller.u_employment_type.label);
g_form.setValue('var_job_title', caller.title);
g_form.setValue('var_department', caller.department);
g_form.setValue('var_reporting_manager', caller.manager);
g_form.setValue('var_company_name', caller.company);
g_form.setValue('var_parent_company', caller.u_user_opco);
g_form.setValue('var_office_location', caller.location);
g_form.setValue('var_mobile_number', caller.mobile_phone);
g_form.setValue('var_logon_id', caller.user_name);
}
Am I missing something here.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 05:21 AM - edited 02-21-2023 05:24 AM
I have checked in the PDI and caller.u_employment_type.label is returning "undefined", so it is not working,
Best way to achieve this is:
1) create a json object as
var json = {"3":"captive","2":"contractor","1":"FTE"};
g_form.setValue('var_employee_type', json[caller.u_employment_type+""]); // caller.u_employment_type will return backend value as 3,2,1 accordingly.
The second method is to use glideRecord on the sys choice table, but I don't think that makes sense because you have to make a glideAjax call to get the values, and the options for your field are limited.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 04:55 AM
Hi,
Try by using Choice field vallue like below.
g_form.setValue('var_employee_type', caller.u_employment_type.value);
Thanks,
Pooja M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 05:21 AM - edited 02-21-2023 05:24 AM
I have checked in the PDI and caller.u_employment_type.label is returning "undefined", so it is not working,
Best way to achieve this is:
1) create a json object as
var json = {"3":"captive","2":"contractor","1":"FTE"};
g_form.setValue('var_employee_type', json[caller.u_employment_type+""]); // caller.u_employment_type will return backend value as 3,2,1 accordingly.
The second method is to use glideRecord on the sys choice table, but I don't think that makes sense because you have to make a glideAjax call to get the values, and the options for your field are limited.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 09:58 PM
Thank You Prince.
Its working perfect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 07:06 AM - edited 02-21-2023 07:15 AM
Hi @Ankita Gupte ,
The getReference() method is not considered best practice, even with a callback function, as it retrieves the complete record while usually you only need one field or two.
The recommended best practice options are g_scratchpad and GlideAjax.
From docs: "GlideRecord and g_form.getReference() are also available for retrieving server information. However, these methods are no longer recommended due to their performance impact. Both methods retrieve all fields in the requested GlideRecord when most cases only require one field."
Use GlideAjax to send value to server and then return display name from server.
You can refer below thread to achieve the functionality:
Please mark this as the correct answer and helpful if it is resolved, or mark this helpful if this helps you to reach the solution.
Thanks & Regards
Jyoti Jadhav