Auto populate asset tag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2018 09:19 AM
Hi All,
We have a service request, in that we need to auto populate Asset tag field(Lets say field name is asset_tag and type is single line text) based on selected user(lets say variable name is requested_for). if user have more than one asset, then asset_tag field should show all the assets assigned to that user. and based on the selected asset os filed should auto populate(lets say os field name is OS).
Kindly help me to achieve this.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 03:51 AM
Unfortunately above code is not working, can you please help me here.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 03:53 AM
Hi
Please share your script.
Please place an alert in client script in callback function. :- alert(answer);
Tell me what is the output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 04:08 AM
I am using the same script which was posted above, and placed alert() in call back but there is no output
function setAssetTag(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer!=''){
//g_form.setValue('ASSET_TAG',answer); // Use your variable name here.
alert(answer);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 04:24 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr= new GlideRecord("alm_hardware");
gr.addQuery("assigned_to",g_form.getValue("requested_for"));// requested_for is variable name on SP when we change this value, based on this value asset_tag_single should auto popule
gr.query(callBack);
function callBack(gr){
if(gr.next()){
count = gr.getRowCount();
if(count >1) {alert("More than one asset is assigned to you, kindly fill asset tag and operating system values manually"+ answer);
//g_form.setValue('asset_tag_reference','');
//g_form.setValue('select_operating_system','');
var answer= gr.asset_tag;
}
else
{ g_form.setValue('asset_tag_single',gr.asset_tag);// asset_tag_single is variable name in SP which should auto populate asset tag from asset table.
var ci= new GlideRecord("cmdb_ci_computer");
ci.addQuery("sys_id",gr.ci);
ci.query(callBack2);
}
}
function callBack2(ci){
if(ci.os="Windows 7 Enterprise"){g_form.setValue("select_operating_system","Windows 7 64-bit(standard)");}
if(ci.os="Windows 10 Enterprise"){ g_form.setValue("select_operating_system","Windows 10");}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 04:24 AM
Hi I have found bellow code it is auto populating asset tag if user has only asset. I need to populate asset_tag if user has more than one asset also. Please review the code and help me on this.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr= new GlideRecord("alm_hardware");
gr.addQuery("assigned_to",g_form.getValue("requested_for"));// requested_for is variable name on SP when we change this value, based on this value asset_tag_single should auto popule
gr.query(callBack);
function callBack(gr){
if(gr.next()){
count = gr.getRowCount();
if(count >1) {alert("More than one asset is assigned to you, kindly fill asset tag and operating system values manually");// I believe we need to change here, kindly provide me correct code which should auto populate asset_tags if user has more than one asset.
//g_form.setValue('asset_tag_reference','');
//g_form.setValue('select_operating_system','');
}
else
{ g_form.setValue('asset_tag_single',gr.asset_tag);// asset_tag_single is variable name in SP which should auto populate asset tag from asset table.
var ci= new GlideRecord("cmdb_ci_computer");
ci.addQuery("sys_id",gr.ci);
ci.query(callBack2);
}
}
function callBack2(ci){
if(ci.os="Windows 7 Enterprise"){g_form.setValue("select_operating_system","Windows 7 64-bit(standard)");}
if(ci.os="Windows 10 Enterprise"){ g_form.setValue("select_operating_system","Windows 10");}
}
}
}