Auto populate the values based on the another field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 06:10 AM
I have created the variables
1. Requested for
2. Requester Manager
3. Country.
When i have selected a requested for then auto populate the manager and country
I am using the glide Ajax method
Script include: Groupmanager
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 07:40 AM
Hi @vinod6 ,
You can use Auto Populate feature to set Requester Manager and Country.
For country in DOT walk Path dot walk to Location -> country
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 07:48 AM - edited 03-18-2024 07:49 AM
Hi @vinod6,
Here's the Client Script and Script Include respectively ready for you to copy and paste.
Please make sure your 'Country' field is of type Single Line Text and not reference.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = g_form.getValue('requested_for');
var ga = new GlideAjax('Groupmanager');
ga.addParam('sysparm_name', 'UserDetails');
ga.addParam('sysparm_usr', user);
ga.getXMLAnswer(calback);
function calback(response) {
var answer = JSON.parse(response);
g_form.setValue('requester_manager', answer.manager);
g_form.setValue('country', answer.countryCode);
}
}
Script Include:
var Groupmanager = Class.create();
Groupmanager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
UserDetails: function() {
var x = this.getParameter('sysparm_usr');
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id', x);
grUser.query();
if (grUser.next()) {
var obj = {};
obj.manager = grUser.manager.toString();
obj.countryCode = grUser.country.toString();
return JSON.stringify(obj);
}
},
type: 'Groupmanager'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 01:32 PM
Hi @vinod6,
The only miss which caused the issue in your script is the script include line var x=this.getparameter it should have been this.getParameter. Debugging script using logs could have helped you in identifying this issue as it gives null value when you use this.getparameter.
Please mark this as helpful if this explanation helped you in understanding the issue.
Thanks & Regards,
K. Sai Charan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 01:38 PM
Hi @vinod6 ,
Create Client script:
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue === '') { return; } //Type appropriate comment here, and begin script below var user = g_form.getValue('u_open_on_behalf'); //make sure about the variable. var ga = new GlideAjax('userdetails'); ga.addParam('sysparm_name','requestor_info'); ga.addParam('sysparm_user_name',user); ga.getXML(HelloWorldParse); function HelloWorldParse(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); var ans = answer.evalJSON(); for (var k = 0; k < ans.length; k++) { alert('Phone Number is ' +ans[k].phone); g_form.setValue('phone_number',ans[k].phone); g_form.setValue('employee_location',ans[k].location); g_form.setValue('employee_id',ans[k].emp); g_form.setValue('employee_supervison',ans[k].manager); g_form.setValue('country ',ans[k].country_code); } } }
Script Include: Make sure the script include should be client callable.
var userdetails = Class.create(); userdetails.prototype = Object.extendsObject(AbstractAjaxProcessor, { requestor_info: function() { var arr=[]; var output=''; var json = new JSON(); var details=this.getParameter('sysparm_user_name'); var user= new GlideRecord('sys_user'); user.addQuery('sys_id',details); user.query(); while(user.next()) { var obj = {}; obj.phone=user.mobile_phone.getDisplayValue(); obj.location=user.location.getDisplayValue(); obj.emp=user.emplpyee_number.getDisplayValue(); obj.manager=user.manager.toString(); obj.country_code=user.location.country.toString(); arr.push(obj); } gs.log('value is :'+ json.encode(arr)); return (json.encode(arr)); }, type: 'userdetails' });