Populate Logged in user details in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 09:40 AM - edited 07-04-2023 09:57 AM
HI, Developers I have below the Type of variables in my catalog item. How can I get These Details with the Script?
Thanks for your time and support.
Requestor Name | Capture the Full Name of the logged in user |
Requestor Location | Capture the "Location Name" of Requested For from sys_user table |
Requestor Mobile Number | Capture the "Mobile Phone" of Requested For from sys_user table |
Project Name (ID) | Look-up to project IDs associated with Requested For |

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 09:51 AM
Looks like you have posted the complete requirement here.
Can you please share what you have tried and where exactly you are stuck?
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 10:03 AM
HI, @Anil Lande I am very new to ServiceNow One of my friends works in ServiceNow I just collected the use case for my knowledge improvement as I am very new to ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 10:08 AM
Inorder to achieve this based on requested for variable. you need to write a onchange client script and then call the client callable script include through glide ajax and populate the variables.
Below is the sample client script code :
var user = g_form.getValue('requested_for'); // requested for
var ajax = new GlideAjax('OffBoarding_Autopopulate'); // script include name
ajax.addParam('sysparm_name', 'getUserDetails'); // function name
ajax.addParam('sysparm_user', user); // user
ajax.getXML(userParse); // call back function
function userParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var users = JSON.parse(answer); // parse response
g_form.setValue('location', users[0].location); //set department
g_form.setValue('phone', users[0].phone); //set phone
g_form.setValue('email', users[0].email); //set email
g_form.setValue('title',users[0].title);// set job title
g_form.setValue('manager', users[0].manager); //set manager
}
Below is the client callable script include sample code:
getUserDetails: function() {
var details = [];
var user = this.getParameter('sysparm_user');
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', user);
userGR.query();
while (userGR.next()) {
var users = {};
users.location = userGR.loaction.toString();
users.email = userGR.email.toString();
users.title = userGR.title.toString();
users.phone = userGR.phone.toString();
users.managerEmail = userGR.manager.email.toString();
users.manager = userGR.manager.name.toString();
details.push(users);
}
return JSON.stringify(details);
},
Please mark it as correct answer, if resolves your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 10:18 AM
hi @Mehta thanks for your solution but in my case, the requester name variable is a read-only variable in the service catalog it has to be filled with the currently logged-in user name based on his name only I need to populated the rest of the data.