Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Field update issue (asset transfer order)

Aaron Brown2
Tera Expert

Greetings!  I have an issue that I hope someone can assist with.  I have a custom application that we use to comply with Secure Supply Chain requirements.  This application utilizes the Transfer Orders capability within servicenow.  On a few occasions, when transfer order lines are removed from a transfer order, the asset does not clear the active_to field.  This naturally causes issues.  We wrote a UI action script to clear the active_to field and set the substatus of the asset to Available instead of Pending transfer.  The script worked in Quebec however it is not working in San Diego.  I have created ACL's to allow editing of fields but the Active_to field seems immuatable.  Can someone assist me with clearning the active_to field for the record we are viewing?

UI Action.onclick = fixAssset()

UI Action.condition = current.install_status==6&&current.substatus=='pending_transfer'

 

function fixAsset() {
    var recordID = g_form.getUniqueValue();
    //alert(recordID);
    var gr = new GlideRecord('alm_hardware');
    gr.addQuery('sys_id', recordID);
    gr.query();
    //alert('Record count: ' + gr.rows.length);

    while (gr.next()) {
        //alert('Setting Active Txfr Order to false');
        gr.active_to = 'false';
        //alert('Setting substate to Available');
        gr.substatus = 'available';
        //alert('Saving Record');
        gr.update();
    }
    action.setRedirectURL(current);
}

 

 requires role = admin

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

That field is "Read only" in my instance, it is defined on the parent table of alm_hardware:

Capture.JPG

You'll need to override that as a start. And the script you have seems more appropriate for use in a Bussiness rule or other server-side means. What does you 'alert' statement show? check the return value of the 'gr.update();'.

View solution in original post

3 REPLIES 3

Bert_c1
Kilo Patron

That field is "Read only" in my instance, it is defined on the parent table of alm_hardware:

Capture.JPG

You'll need to override that as a start. And the script you have seems more appropriate for use in a Bussiness rule or other server-side means. What does you 'alert' statement show? check the return value of the 'gr.update();'.

Bert_c1
Kilo Patron

Your UI Action can run on either the client or server, see:

 

https://docs.servicenow.com/bundle/tokyo-application-development/page/script/general-scripting/refer...

 

and check to see that it is configured to run on server-side.

Aaron Brown2
Tera Expert

Wow...I am a total idiot.  Easiest solution.  I thought it was an ACL on the table so I created a write rule on alm_asset.active_to.  

As for the script being more appropriate for another use, I am still learning how to do things but when I tried client side it wouldn't work so I tried using server side and it worked in Quebec.  

 

Thank you for the read-only attribute.  I cannot believe I didn't check the table first.  DERP!