Autopopulate the fields(country, Region) in catalog item as user login
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 03:02 AM
Hi everyone,
In catalog item for logged- in user country and region needs to be auto populated. we have a variable set were we get values of Requested for(user name from sys_user table) and location(deatils from cmn_loaction table) which is auto populated. In the same way need a onload client script to Auto Populate 'Country' and 'Region'(Single Line text fields) for logged in user (using the location field present in variable set).
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 03:16 AM
Hi @Sharada N S,
Please find the below link.
https://www.servicenow.com/community/itom-forum/auto-populate-the-computer-name-field/m-p/2382602/pa...
Thanks
SP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 08:15 AM
Hi @Sharada N S,
You can create a client script and script include to auto-populate the details. Please find the below link for reference.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 08:46 AM
Hi @Sharada N S ,
You can create a onload client script and call script include and return the value countrey and region and set it in the form
Client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var sys_id = g_user.userID;
var glAj = new GlideAjax('getUserCountry');
glAj.addParam('sysparm_name','getUser');
glAj.addParam('sysparm_sysId', sys_id);
glAj.getXML(getResponse);
}
function getResponse(response){
var ans = response.responseXML.documentElement.getAttribute('answer').split(',');
alert('ans' + ans);
g_form.setValue('country', ans[0]);
g_form.setValue('region',ans[1]);
}
Script include:
var getUserCountry = Class.create();
getUserCountry.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUser: function(){
var sys =this.getParameter('sysparm_sysId');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',sys);
var arr = [];
gr.query();
if(gr.next()){
arr.push(gr.location.country.toString());
arr.push(gr.location.state.toString());
}
gs.info('country is ' + arr);
return arr.toString();
},
type: 'getUserCountry'
});
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang