- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 02:31 AM
Hi,
I have created a Script Include and Client Script however it is working fine when I select one custodian Name and it's autopopulating the Custodian L4 Name however when I select two user in Custodian Name it's not autopopulating the another person Custodian L4 Name 2 that I have created another field. Please let me know the resolution of the same based on the below script attached for the reference and let me know in case of any query,
SCRIPT INCLUDE SCRIPT
Custodian L4 Name
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 04:53 AM
Hi @Naman Jain2412 ,
As per your script it looks like Field "Custodian Name" is of type "LIST".
Please find the working script:
SCRIPT INCLUDE SCRIPT
Custodian L4 Name:
autopopulateL4Name: function() {
var userIDs = this.getParameter('sysparm_user_id');
var userIDArray = userIDs.split(',');
var result = [];
for (var i = 0; i < userIDArray.length; i++){
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', userIDArray[i]);
userGR.query();
if (userGR.next()) {
result.push(userGR.department.u_l4_headempcode.getDisplayValue());
}
return result.toString();
},
});
CLIENT SCRIPT
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Check if a user is selected
var userID = g_form.getValue('u_custodian_name');
var ga = new GlideAjax('sn_compliance.Autopopulate_L4_Name');
ga.addParam('sysparm_name', 'autopopulateL4Name');
ga.addParam('sysparm_user_id', userID.toString());
ga.getXML(pop_details);
function pop_details(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split(',');
g_form.setValue('u_custodian_l4_name', values[0]);
g_form.setValue('u_custodian_l4_name2', values[1]);
}
}
It's working in PDI 🙂
Let me know if you still stuck somewhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 06:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2025 05:13 AM
It is working however when I am saving the form it's automatically clear the field value. can you pls let me know which should be added so that it doesn't clear the value & data should also available when we check show XML.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2025 05:18 AM
Can you share your client script
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2025 05:41 AM