Catalog Item Variable query a users record and populate select box variable as yes or no
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 06:28 AM
Hi all,
So on one of our catalog items when a user is selected in a reference field we want it to query one of the custom fields on that users sys_user record and depending on if there is a semi-colon ";" (which depicts that the user has multiple codes in that variable separated by a semi-colon) in there it will update another variable on the catalog form as "Yes". If there is no semi-colon then it will set it to "No" which will also be the default setting.
I have the following script which doesn't seem to be working. Any tips on what needs to change for this to work?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading){
return;
}
if (newValue == '') {
g_form.setValue('does_the_partner_own_more_than_one_practice', 'no');
}
if (oldValue == newValue){
return;
}
var id ='';
id = newValue;
//alert('sys_id of user : ' + id);
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", id);
user.addQuery("u_principal_partner", "CONTAINS", ";");
user.query();
if (user.next()) {
g_form.setValue('does_the_partner_own_more_than_one_practice', 'yes');
} else if (!user.next()){
g_form.setValue('does_the_partner_own_more_than_one_practice', 'no');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 07:09 AM
Using a GlideRecord in a Client Script is neither supported or recommended. Having said that, simple queries like this usually work in the native UI. Aside from the ridiculously long variable name, logically you don't need an else if, just an else, but neither are probably not preventing this from working. Ensure the custom field name and variable name are exactly correct, and that variable values are correct - should they be 'Yes' and 'No'?
A supported way to do this is by using getReference
Your callback function would set the variable value inside of an if condition to check the custom field for the semicolon.