Asset Substate not updating from UI page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 10:10 AM
I have a UI page which updates records on alm_asset - we use this for replacing unsupported kit, so it removes a new reserved asset from a stock room, updates the asset tag, location and state. It also sets the state of the old asset to retired and populates the comments and disposal reason. However, I cannot for the life of me get it to update substate on either assets, even though the logs return the desired value
Here's a snippet of code for retiring the old asset. As you can see from the comments, I have tried placing the substate in various place before and after updating state but i'm having no joy:
if(oldAsset != ""){
//alert("test");
var gr6=new GlideRecord("alm_asset");
gr6.addQuery("sys_id",assetTag);
gr6.query();
while(gr6.next()){
var gr5=new GlideRecord("alm_asset");
gr5.addQuery("sys_id",oldAsset);
gr5.query();
while(gr5.next()){
var replacement = gr6.asset_tag;
//gr5.install_status = "7";
gr5.substatus = '--none--';
gr5.update();
console.log(gr5.substatus);
// gr5.substatus = 'pending_disposal';
gr5.update();
gr5.install_status = "7";
console.log(gr5.install_status);
gr5.update();
// gr5.substatus = 'pending_disposal';
gr5.update();
console.log(gr5.substatus);
// gr5.update();
gr5.location= "4cda60a41b445110915c620be54bcba6";
// gr5.update();
gr5.disposal_reason = comments;
gr5.comments= "Replaced by " + replacement + " - " + comments + " - " + incNum;
gr5.company= "71f448c71b720510349f40c4e34bcbd3";
// gr5.substatus= "pending_disposal";
gr5.update();
// console.log(gr5.substatus);
//g_form.setValue('substatus', "pending_disposal" );
//setValue(gr.substatus, "pending_disposal");
//gr5.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 10:47 AM
Hi,
I do not see a sys_choice value of '--none--' Like I see 'pending_disposal'. try using '' (null string). All records in alm_asset in my instance match query: substatus=
Good luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 10:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 12:52 PM
Hi Ray,
I got the following to work in Scripts Background:
var assetRec = new GlideRecord('alm_asset');
assetRec.initialize();
assetRec.display_name = 'Test Asset';
assetRec.substatus = 'lost';
var insertResult = assetRec.insert();
gs.info("Insert result = " + insertResult);
However, the display_name didn't work. the for that record I created I tried:
var assetRec = new GlideRecord('alm_asset');
assetRec.addQuery('sys_id', '2f4df99747c4f110753923dbd36d43f2');
assetRec.query();
if (assetRec.next()) {
assetRec.display_name = 'Test Asset';
assetRec.substatus = '';
var updateResult = assetRec.update();
gs.info("Update result = " + updateResult);
}
And that cleared the substatus value. So there is more going on here. I did find one ACL
But again, my test to update substatus above did work. More testing is needed for your code. I have no idea where that code resides.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2023 08:39 AM - edited ‎07-25-2023 08:39 AM
hi @Bert_c1
You were correct about the substatus value. However the issue was down to my own stupidity - I had cloned and renamed the UI page but hadn't changed the page name in the HTML (update_asset.php). Once I changed this and set substatus= "", it worked.