- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 01:18 AM
Hi,
By selecting the Opened for I want to Auto populate Contact number by using the Sciptinclude please help me out with the Sciptinclude and onChange client script for the same.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2023 10:40 PM
check the end user had read access of user table record or not
Mark this answer as correct and helpful if it helps
Thanks,
Manjusha Bangale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 01:46 AM
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name', 'getCallerContact');
ga.addParam('sysparm_caller', g_form.getValue('opened_for'));//put correct backend value of opened for
ga.getXML(setContactDetail);
}
function setContactDetail(response) {
var contact_num = response.responseXML.documentElement.getAttribute("answer");
if(contact_num){
g_form.setValue('contact_number', contact_num);//replace contact_number with correct backend name
}
}
Script Include:
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCallerContact: function() {
var contact_no = '';
var user_sysid = this.getParameter('sysparm_caller');
var userObj = new GlideRecord("sys_user");
userObj.addQuery("sys_id", user_sysid);
userObj.query();
if (userObj.next()) {
contact_no = userObj.contact_number;//update contact_number with correct backend name
}
return contact_no;
}
});
Mark this answer as correct and helpful if it helps
Thanks,
Manjusha Bangale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 10:51 PM
Hi @manjusha_
Sorry for the late response i have used the same script with contact number modifications but it is not working as expected. hence contact number is not populating
please find the below mentioned Screenshots for the same.
Scriptinclude:
onChange:
Variable name:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 01:50 AM
u_pre_contact is the variable to which you want to set the contact details taken from the user table for respective caller id ,also add correct backend name of caller_id field in your client script as below
ga.addParam('sysparm_caller', g_form.getValue('opened_for'));//replace opened_for with correct backend name of caller id variable
In your script include function code you mentioned u_pre_contact which is not correct ,you should specify the backend name of contact number field present on User table
Check the user table and get the field backend name from there and put in your code
getCallerContact: function() {
var contact_no = '';
var user_sysid = this.getParameter('sysparm_caller');
var userObj = new GlideRecord("sys_user");
userObj.addQuery("sys_id", user_sysid);
userObj.query();
if (userObj.next()) {
contact_no = userObj.contact_number;//update contact_number with correct backend name from the user table contact field which you want to update on the u_pre_contact variable
gs.info("MyContactNumber:- "+contact_no);//put log and check the value of contact number field in system logs module
}
return contact_no;
}
Mark this answer as correct and helpful if it helps
Thanks,
Manjusha Bangale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2023 08:10 PM
Hi @manjusha_ I have tried this which is working fine but if i login as a End user then auto populate option is not working.
Thanks,