- 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-17-2024 05:45 AM
Hi @Revathi12 ,
I tried your problem in my PDI and it works for me, Please refer below image
I created onChange client script and add below code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
alert("New Value = " + newValue);
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', newValue);
gr.query();
if(gr.next()){
g_form.showFieldMsg('select_user', gr.user_name, "info");
}
}
You can add showFieldMsg method to show the id
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 07:09 AM
Hello @Community Alums
Thanks for the response. I have tried using Ajax calls, Could you please let me know if I'm missing something here
SI :-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 08:02 AM
Hi @Revathi12 ,
I checked your code there is two small issues I got and I fixed them please try below code
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('name'));
}
gs.info("TestUserID" + users);
return users.toString();
},
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
alert('Here showUserId = ' + newValue);
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);
}
}
I hope this will work fine now
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:11 AM
Hi @Community Alums
I wanted to display user as field message. There is a variable, when we select user as input below it should display field message of user id selected in user field.