
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 09:09 AM
I want show the user first name and mobile number when caller field changes. I am trying to use a client script to call a script include to do this. I did set Client callable to true .But I am getting null value.
client script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 05:19 PM
When you add Parameters to a Client Script and retrieve them in the Script Include, the name must start with sysparm_, not sysparam_ so your Client Script will look like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.setReadOnly('u_custom_mobile', true);
g_form.setReadOnly('u_first_name', true);
return;
}
alert('Script Runs '+g_form.getValue('caller_id'));
var gx = new GlideAjax('userDetails');
gx.addParam('sysparm_name', 'callernameandphone');
gx.addParam('sysparm_user', g_form.getValue('caller_id'));
gx.getXML(getData);
function getData(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
alert(answer);
if(answer) {
var temValue = answer.toString().split('|');
g_form.setValue('u_custom_mobile', temValue[0]);
g_form.setValue('u_first_name', temValue[1]);
}
}
}
and the Script Include:
var userDetails = Class.create();
userDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
callernameandphone: function() {
var usrId = this.getParameter('sysparm_user');
var gr = new GlideRecord('sys_user');
if (gr.get(usrId)) {
return gr.getValue('mobile_phone') + '|' + gr.getValue('first_name');
}
},
type: 'userDetails'
});
You can further troubleshoot this by adding more alerts to the Client Script and gs.info lines to the Script Include to confirm it's running, and see the parameter values and how far it is getting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 07:19 PM
Hello @Community Alums,
Please correct these two line syntax:
gx.addParam('sysparm_name', 'callernameandphone');
gx.addParam('sysparm_user', g_form.getValue('caller_id'));
Using getReference():
Client Script details:
Type: onChange
Table: Incident
Field Name: Caller
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var caller = g_form.getReference('caller_id');
g_form.setValue('department',caller.department);
g_form.setValue('location',caller.location);
g_form.setValue('email',caller.email);
g_form.setValue('name',caller.name);
g_form.setValue('Mobile phone',caller.mobile_phone);
}
If my answer is helpful please mark it as helpful or correct!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:47 PM
Using "getReference" is not the best for performance reasons:
- you are not using a call back function
- it returns a light-weight GlideRecord with all the data in the record instead of just the bits we need
- in your example, although NOT required by the OP, setting the Department and Location field would trigger 2 more calls back to the server to get the display values for those records
As I mentioned above, take a look at this post for an alternative method: TNT: Returning Data from GlideAjax Calls
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2024 12:55 AM - edited 10-04-2024 12:56 AM
Hi Nagarjuna,
Please try this once
var caller = g_form.getReference('caller_id', getDetails); // getDetails is our callback function
function getDetails(caller) { //reference is passed into callback as first arguments
g_form.setValue('u_custom_mobile', caller.mobile_phone);
g_form.setValue('u_first_name', caller.first_name);
}
Regards,
Ramesh