How to auto populate asset and manager details based on a user

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2020 09:58 PM
I'm trying to great a form that our users would use if they need to report an asset has been lost/stolen or broken and I'm trying to auto populate as much detail as I can so those filling it in don't have a heap to do, but those receiving the notification will have all details that they need.
So based on the name of the asset user I would like to populate all their details (phone, email, logon ID, desk location, etc) which I've been able to do except for some reason the phone number isn't playing the game.
Then I can get the managers name, but can't work out how to populate their email and phone number.
I would also like to populate a select box with only the assets that are assigned to name of the asset user.
EG:
My variable names are:
Would really appreciate some help, Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2020 10:27 PM
Hi,
so you would require onChange client script here + Script Include + GlideAjax
In the script include function form a json object of whatever value you want to set
1) onchange of asset owner script get the json and parse it and set the values to every required field
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2020 10:52 PM
Hi,
Please find the below thread it might help you.
Regards
Nikhil

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 08:59 PM
Sorry
Thank you both however for at least looking and trying to assist, I do always appreciate that someone tries to help me, even if I don't personally find it helpful myself.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 10:43 PM
Hello Moedeb,
Sorry to interrupt in between, I would like to add something which might resolve this query,
could you please share the code which you have written if it is?
for the same you can write script include with multiple functions which guide sys_user and alm_asset tables to get the necessary details and associated onChange catalog client scripts.
e.g.
I have write one script include and client scripts to get details something like your requirement
SCRIPT INCLUDE
getData: function()
{
var sysid=this.getParameter("sysparm_id");
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", sysid);
gr.query();
var arr1=[];
while (gr.next())
{
return gr.email;
//gs.addInfoMessage("email= "+email);
}
},
getAssetData: function()
{
var sysid=this.getParameter("sysparm_id");
var gr=new GlideRecord('alm_asset');
gr.addQuery('assigned_to',this.getParameter("sysparm_id"));
gs.addInfoMessage("sys_id in asset function "+sysid);
gr.query();
var arr=[];
while(gr.next())
{
arr.push(gr.getValue("display_name")+" ");
}
return arr.toString();
},
type: 'GetDetails'
});
CLIENT SCRIPT:
1:For email
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga=new GlideAjax('GetDetails');
ga.addParam('sysparm_name','getData');
ga.addParam('sysparm_id',newValue);
ga.getXML(callback);
function callback(response)
{
var ans=response.responseXML.documentElement.getAttribute('answer');
g_form.setValue("requested_for_email",ans);
}
}
2:For asset
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga=new GlideAjax('GetDetails');
ga.addParam('sysparm_name','getAssetData');
ga.addParam('sysparm_id',newValue);
ga.getXML(callback);
function callback(response)
{
var ans=response.responseXML.documentElement.getAttribute('answer');
g_form.setValue("assets",ans);
}
}
You need to just add function in script include to get manager details and associated catalog client script to set those values into the variables.
Hope this will help you to resolve your query.
Kindly mark the answer correct and helpful if it will resolved your query.
Regards,
Akshata
(ServiceNow Developer).