- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 05:04 AM
Hi Team,
I have variable user which is reference to sys_user and I need to populate the user ID of the user as field message. I tried with showfieldMessage but no luck. Can anyone help me on this.
Thanks
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 04:09 AM
@Revathi12 remove single inverted comma from ans
g_form.showFieldMsg('user', ans , 'info');
Try with the above
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 10:01 AM - edited 04-23-2024 10:03 AM
Hi @Revathi12 ,
Please update your client script code as below
Script Include
getUserID: function() {
var users = [];
var id = this.getParameter('sysparm_user_name');
gs.log('IDIID = ' + id);
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
while (gr.next()) {
users.push(gr.getValue('user_name'));
}
gs.info("TestUserID" + users);
return users.toString();
},
Client Script
var ga = new GlideAjax('catalogCS');
ga.addParam('sysparm_name', 'getUserID');
ga.addParam('sysparm_user_name', newValue);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.showFieldMsg('select_user', answer, "info");
}
Here's the result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 08:22 AM
Hi @Revathi12 ,
I have updated your code below ,
It will show you the user id of the user selected
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// alert(newValue);
var ga = new GlideAjax('TestUserID');
ga.addParam('sysparm_name', 'getUserID');
ga.addParam('sysparm_userID', newValue);
ga.getXML(getResults);
}
function getResults(response) {
var ans = response.responseXML.documentElement.getAttribute("answer");
// alert(ans);
if (ans != '') {
g_form.showFieldMsg('user', ans, 'info');
}
}
SI:
var TestUserID = Class.create();
TestUserID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserID: function() {
var users = [];
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',id);
gr.query();
if(gr.next()) {
// gs.info('inside if');
users.push(gr.getValue('user_name'));
}
// gs.info("TestUserID" + users);
return users.toString();
},
type: 'TestUserID'
});
In si just replace gr.getValue('user_name');
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 08:31 AM
Hi @SwathiSarang ,
Thanks for response.
I checked the code, its printing the answer instead of user ID.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 08:58 AM
Hi @Revathi12 ,
yes because ans will have the user id actually which will be coming from script include.
Did you copy the code exactly and do make changes for field name if it is different
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 08:59 AM
@Revathi12 i have tried it in my pdi it works,
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang