Function setDisplayValue is not allowed in scope XYZ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 06:48 AM
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 way to deal with this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 06:58 AM
Hello,
Show the code ? set display should work in scope app, see below links for reference
https://community.servicenow.com/community?id=community_question&sys_id=506acd89dbda049023f4a345ca9619d8
https://community.servicenow.com/community?id=community_question&sys_id=878451571bc15810ada243f6fe4bcb85
Regards
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 12:21 PM
When 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__.
can you help me out 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();
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 12:30 PM
Hey,
I believe the fields that you have on catalog item, are those reference fields or string?
If reference, then you don't even need to use setDisplayValue, you can just use setValue() for this.
And if you still want to use setDisplayValue(), use this way:
alm.transfer_order.setDisplayValue(parentID); // obj.field_name.setDisplayValue(value);
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 01:24 AM
Hi Aman,
Thanks for your respose,
But it is not working. still I am facing the same issue.
Error Message