- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 08:27 AM
When ever i select Caller id i need to populate email, phone, manager name, & title, this i need to get using Script include.
PLEASE HELP ME OUT on this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 09:09 AM
Hi,
For Auto population of the above defined Variables you can write an Script Include and call the same Script Include in an OnLoad Catalog Client Script as mentioned below:
Script Include:
var requestor_details = Class.create();
requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
requestor_info: function() {
var result = this.newItem("result");
var logged_user = gs.getUserID();
var user_detail = new GlideRecord('sys_user');
user_detail.addQuery('sys_id',logged_user);
user_detail.query();
while(user_detail.next())
{
result.setAttribute("user",user_detail.sys_id);
result.setAttribute("phone", user_detail.phone);
result.setAttribute("email",user_detail.email);
result.setAttribute("location",user_detail.location);
}
},
type: 'requestor_details'
});
2) Then you can write an On Load Catalog Client Script wither on your Catalog Item or on the Variable Set to have the variables populated as shown below:
Script:
function onLoad()
{
var ga = new GlideAjax("requestor_details");
ga.addParam("sysparm_name","requestor_info");
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var result = serverResponse.responseXML.getElementsByTagName("result");
var phone = result[0].getAttribute("phone");
var user = result[0].getAttribute("user");
var email = result[0].getAttribute("email");
var loc = result[0].getAttribute("location");
g_form.setValue('requestor_phone',phone);
g_form.setValue('requestor_name',user);
g_form.setValue('Location_user',loc);
}
}
Replace your Variable Name appropriately in the Set Value Conditions say for example in place of the variable "Location_user" with your Location Variable.
In a Similar Way you can try for other Variables also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 08:46 AM
Hi Shaik,
Use an onChange catalog client script. It should work for your needs.
- function onChange(control, oldValue, newValue, isLoading) {
- var id = g_form.getValue('u_first_field');//replace 'u_first_field' with the name of your reference field.
- var user = new GlideRecord('sys_user');
- user.addQuery('sys_id',id);
- user.query();
- if ( user.next() ) {
- g_form.setValue('u_manager_field', user.manager);
- g_form.setValue('u_last_name', user.last_name);
- g_form.setValue('u_whatever', user.field_on_sys_user);
- }
- }
Note: Modify the above Script accordingly.
Thank you.
Rohith.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 08:49 AM
Rohith,
I already achived this via client scirpt since Glide Record is not a Best practice to use in Client script my manager asked me to implement same via Script include.
Can you please help me out ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 09:09 AM
Hi,
For Auto population of the above defined Variables you can write an Script Include and call the same Script Include in an OnLoad Catalog Client Script as mentioned below:
Script Include:
var requestor_details = Class.create();
requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
requestor_info: function() {
var result = this.newItem("result");
var logged_user = gs.getUserID();
var user_detail = new GlideRecord('sys_user');
user_detail.addQuery('sys_id',logged_user);
user_detail.query();
while(user_detail.next())
{
result.setAttribute("user",user_detail.sys_id);
result.setAttribute("phone", user_detail.phone);
result.setAttribute("email",user_detail.email);
result.setAttribute("location",user_detail.location);
}
},
type: 'requestor_details'
});
2) Then you can write an On Load Catalog Client Script wither on your Catalog Item or on the Variable Set to have the variables populated as shown below:
Script:
function onLoad()
{
var ga = new GlideAjax("requestor_details");
ga.addParam("sysparm_name","requestor_info");
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var result = serverResponse.responseXML.getElementsByTagName("result");
var phone = result[0].getAttribute("phone");
var user = result[0].getAttribute("user");
var email = result[0].getAttribute("email");
var loc = result[0].getAttribute("location");
g_form.setValue('requestor_phone',phone);
g_form.setValue('requestor_name',user);
g_form.setValue('Location_user',loc);
}
}
Replace your Variable Name appropriately in the Set Value Conditions say for example in place of the variable "Location_user" with your Location Variable.
In a Similar Way you can try for other Variables also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 09:14 AM
Thanks Rohith ,
Can i do this using onChange ?
Mine is Incident table