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

RaghavSh
Kilo Patron

Try using : var too = current.variables.to_stockroom.toString();

Sometimes without toString() does not work in scoped app


Raghav
MVP 2023

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Munna,

There's no .setDisplayValue() in scoped application. It's only supported in Global.

Check the documentation to confirm.

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/no-namespace/c_GlideRecordSc...

It's necessary to use setValue() or use dot notation.

e.g.

var to = new GlideRecord('alm_transfer_order');
to.initialize();
to.from_stockroom = fl.toString();
to.to_stockroom = too.toString();
to.from_location.name = frloc.toString();
to.location.name = toloc.toString();

 

                alm.request_line = current.getUniqueValue();
                alm.transfer_order = parentID;
                alm.model = aset.model;
                alm.asset = aset;
                alm.Value.quantity_requested = 1;

Hi Hitoshi,

I have tried using setValue and dot notation as you mentioned above

But it showing Error message 

Error - Severe inconsistency between asset and transfer order line