I want to load the user name of a reference variable into the another variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 07:53 AM
I want to load the user name of a reference variable into the another variable
it_director_business_app (user selected from sys_user table)
it_director (to be used to send an notification)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 08:11 AM
You would have to use getReference with a callback or a GlideAjax call to a script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 08:33 AM
You can possibly have the field be dependent on that reference field.
Or you can have the field dot-walk to the reference record.
Did this for a project I was on where, in form builder, you can add a field for [reference_field].[field]
This will work like an onchance client script but do the ajax work for you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 09:05 AM
Hi @Bret Smith Try calling script include from onChange Client script on IT Director Business App field.
Script Include : getUserName
var GetUserName = Class.create();
GetUserName.prototype = {
initialize: function() {},
getUserNameById: function(userId) {
var userGr = new GlideRecord('sys_user');
if (userGr.get(userId)) {
return userGr.name; // or userGr.user_name depending on your needs
}
return '';
}
};
onChange Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetUserName');
ga.addParam('sys_id', newValue);
ga.getXMLAnswer(function(response) {
var username = response;
g_form.setValue('it_director', username);
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 09:54 AM
I still get a blank variable on my form
Script Include
GetITDirectorName