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

Moedeb
Tera Guru

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:

find_real_file.png

My variable names are:

find_real_file.png

Would really appreciate some help, Thanks in advance

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Nikhil Phalke
Kilo Guru

Hi,

 

Please find the below thread it might help you.

https://community.servicenow.com/community?id=community_question&sys_id=a218c76ddb1cdbc01dcaf3231f96...

 

Regards

Nikhil

Moedeb
Tera Guru

Sorry @Ankur Bawiskar  but I don't really find your idea helpful, If I knew how to write the onchange script I would do it, but unfortunately I definitely am just a amateur when it comes to this stuff.

 

@Nikhil Phalke sorry I'd checked that already and I really need something that is way more specific for my ability.

 

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.

Akshata jamdar
Mega Guru

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).