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.

setDisplayValue not working for scoped app

Munna1
Tera Contributor

HI Everyone,

I am trying to use setDisplayValue within workflow run script activity.

When I do so, I get the following error.
Error: Function setDisplayValue is not allowed in scope xyz__.

Is there any workaround for this?


Run Script code : 

var too = current.variables.to_stockroom;
var fl = current.variables.from_stockroom;
var toloc = current.variables.to_stockroom.location.name;
var frloc = current.variables.from_stockroom.location.name;
var frStockName = current.variables.from_stockroom.getDisplayValue();

var to = new GlideRecord('alm_transfer_order');
to.initialize();
to.setDisplayValue('from_stockroom', fl); //current.variables.<name of variable>
to.setDisplayValue('to_stockroom', too);
to.setDisplayValue('from_location', frloc);
to.setDisplayValue('to_location', toloc);
to.insert(); //creating transfer order record based on the variables
var parentID = to.number;
var attachID = "";

var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', current.sys_id);
sctask.query();
if (sctask.next()) {
    var gr = new GlideRecord('sys_attachment');
    gr.addQuery('table_sys_id', sctask.sys_id); //Get excel sheet attachment sys_id
    gr.orderByDesc('sys_created_on');
    gr.setLimit(1);
    gr.query();
    if (gr.next()) {
        attachID = gr.sys_id;
    }
}

var row = '';
var inputStream = new GlideSysAttachment().getContentStream(attachID); //Passing the attachement sys_id

var parser = new sn_impex.GlideExcelParser();
parser.parse(inputStream);

var headers = parser.getColumnHeaders();
var header1 = headers[0];

while (parser.next()) {
    row = parser.getRow();
    if (row[header1] != null) {
        var aset = new GlideRecord('alm_hardware'); //Querying assets in hardware table
        aset.addEncodedQuery('stockroom!=NULL^serial_number=' + row[header1]);
        aset.query();
        if (aset.next()) {
            if ((aset.stockroom != fl) || (aset.substatus == 'pending_transfer') || (aset.substatus == 'Law hold') ||(aset.install_status != '6')) {
                if (aset.stockroom != fl) {
                    current.work_notes = 'Invalid Insert: ' + row[header1] + ' does not belong to the Stockroom: ' + frStockName;
                } else if (aset.substatus == 'pending_transfer') {
                    current.work_notes = 'Invalid Insert ' + row[header1] + ' asset already on an active transfer order line ';
                }
                else if (aset.substatus == 'Law hold') {
                    current.work_notes = 'Invalid Insert ' + row[header1] + ' asset is under Law Hold, cannot create transfer order line ';
                } else if (aset.install_status != '6') {
                    current.work_notes = "Invalid Insert: " + row[header1] + " asset is not in 'In Stock' State";
                }
            } else {
                var alm = new GlideRecord('alm_transfer_order_line'); //If the conditions matches above criteria create a new order
                alm.initialize();
                alm.setDisplayValue('request_line', current.getUniqueValue());
                alm.setDisplayValue('transfer_order', parentID);
                alm.setDisplayValue('model', aset.model);
                alm.setDisplayValue('asset', aset.display_name);
                alm.setDisplayValue('quantity_requested', 1);
                alm.insert();
                var childID = alm.number;

                var m2m = new GlideRecord('u_m2m_tasks_assets');
                m2m.initialize();
                m2m.u_asset = aset.sys_id;
                m2m.u_task = current.getUniqueValue();
                m2m.insert();
            }

        }
    }

5 REPLIES 5

Hi,

That seems to indicate the values are being set. Now, the problem is with something different.

Can it be the Transfer Order Line is in Reserved status?

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0789128