- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 09:23 AM
Hello,
I have a requirement to auto fill the user fields based on a reference field on our table. I am still missing something because it shows the answer of Null and I am not see why. Below are my two scripts.
AJAX / Script Include:
Client Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 09:54 AM
Here is the final client script that worked and ended up needed a condition added that I didn't realize until I was testing.
Client Script:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 09:25 AM
@Annette Kitzmil Instead of posting the script include code, you posted client script twice. Can you provide the code of script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 09:42 AM
My apologies...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 09:56 AM
Hi @Annette Kitzmil ,
Please try below code:-
Server side code
getUserLanID: function() {
var LanID = this.getParameter('LanID');
var openedBy = new GlideRecord('sys_user');
openedBy.addQuery('user_id', LanID);
openedBy.query();
if (openedBy.next())
return (JSON.stringify(openedBy);
},
client side code:-
function onLoad(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('clientUtilsCustom');
ga.addParam('sysparm_name', 'getUserLanID');//this calls the AJAX script
ga.addParam('sysparm_LanID', '');//this would be for the user_name which is the LanID
ga.getXML(getResp);
}
function getResp(response) {
var answer=response.responseXML.documentElement.getAttribute("answer"));
answer= JSON.parse(answer);
g_Form.setValue('name', answer.name)
}
Regards,
Ranjit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 10:38 AM
Very close, now I get this: