Asset Substate not updating from UI page

ray evans
Tera Guru

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();
}
}

5 REPLIES 5

Riya Verma
Kilo Sage
Kilo Sage

Hi @ray evans ,

 

Hope you are  doing great.

TRy using below script :

 

if (oldAsset != "") {
    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;

            // Setting the substate to '--none--' for the old asset
            gr5.substate = '--none--';
            gr5.update();

            // Updating the substate to 'pending_disposal' for the old asset
            gr5.substate = 'pending_disposal';
            gr5.update();

            // Setting the install_status to "7" (retired) for the old asset
            gr5.install_status = "7";
            gr5.update();

            // Setting the location, disposal reason, and comments for the old asset
            gr5.location = "4cda60a41b445110915c620be54bcba6";
            gr5.disposal_reason = comments;
            gr5.comments = "Replaced by " + replacement + " - " + comments + " - " + incNum;
            gr5.company = "71f448c71b720510349f40c4e34bcbd3";

            // Updating the old asset with all the changes
            gr5.update();

            // Setting the substate to '--none--' for the new asset
            gr6.substate = '--none--';
            gr6.update();

            // Updating the substate to 'pending_disposal' for the new asset
            gr6.substate = 'pending_disposal';
            gr6.update();

            // Setting the location, disposal reason, and comments for the new asset
            gr6.location = "4cda60a41b445110915c620be54bcba6";
            gr6.disposal_reason = comments;
            gr6.comments = "Replaced by " + replacement + " - " + comments + " - " + incNum;
            gr6.company = "71f448c71b720510349f40c4e34bcbd3";

            // Updating the new asset with all the changes
            gr6.update();
        }
    }
}

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma