fields are not auto-filling in the mobile agent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 03:41 PM
Hello,
I am having an issue getting the incident location and phone field to auto-fill with the affected user's details in the mobile agent on incident form. I am also trying to get the affected user be the same as caller when the caller field is changed . All of this must happen before save. I created a client script with script include and it is not working. Please help.
Client Script
function onChange(control, oldValue, newValue, isLoading) {
// Skip if the form is loading
if (isLoading || !newValue) {
return;
}
// Create a new GlideAjax object for the Script Include
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name', 'getUserLocationAndPhone');
ga.addParam('sys_id', newValue); // Pass the affected user's sys_id
ga.getXMLAnswer(function(response) {
var userDetails = JSON.parse(response); // Parse the JSON response
// Check if the response has values
if (userDetails) {
g_form.setValue('location', userDetails.location); // Set the location field
g_form.setValue('u_phone', userDetails.phone); // Set the custom phone field
}
});
}
Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 08:01 PM
Hi @Rhonda9 ,
These is issue in script like you need to pass the value as "sysparm_sys_id" not ony "sys_id" make these changes both in client script and script include
please try below one
Client script
function onChange(control, oldValue, newValue, isLoading) {
// Skip if the form is loading
if (isLoading || !newValue) {
return;
}
// Create a new GlideAjax object for the Script Include
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name', 'getUserLocationAndPhone');
ga.addParam('sysparm_sys_id', newValue); // Pass the affected user's sys_id -//sysparm_sys_id
ga.getXMLAnswer(function(response) {
var userDetails = JSON.parse(response); // Parse the JSON response
// Check if the response has values
if (userDetails) {
g_form.setValue('location', userDetails.location); // Set the location field
g_form.setValue('u_phone', userDetails.phone); // Set the custom phone field
}
});
}
Script include :
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserLocationAndPhone: function() {
var userId = this.getParameter('sysparm_sys_id'); // Get the sysparm_sys_id from the client script
var result = {};
if (userId) {
var userGR = new GlideRecord('sys_user'); // Query the sys_user table
if (userGR.get(userId)) {
result.location = userGR.location.getDisplayValue(); // Use display value for location field
result.phone = userGR.getValue('u_phone'); // Ensure 'u_phone' is the correct field name
}
}
return JSON.stringify(result); // Return the result as a JSON string
},
Please mark helpful & correct answer if it's really worthy for you.
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 10:00 PM
Thank you, I adjusted the scripts and it still is not working....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 01:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 03:48 AM
I tried all and mobile.