Error Trying to Update Records in Custom Table in Scoped App with Background Scripts

jmiskey
Kilo Sage

I have a Scoped App that has a Custom Table with about 150 records in it.  This has been in Production for a while.  They want to add a suffix onto one of the fields for all records.  The field name is called "security_group", and they want to add "- Role" to the end of every entry of this field.

 

I created the following Background Script to do that:

var gr = new GlideRecord('x_table_name');
gr.addQuery('active','true');
gr.query();

while(gr.next()){
	gr.security_group = gr.security_group + '- Role';
	gr.update();
}

when I try to run it, I get the following error messages:

Security restricted: Write operation against 'x_table_name' from scope 'rhino.global' has been refused due to the table's cross-scope access policy

 

I did some research, and found the following articles:

https://www.servicenow.com/community/developer-forum/quot-write-operation-from-scope-rhino-global-ha...

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

 

I have tried the suggestions in them, including:

1. Tried a "cache.do"

2. Tried running  "gs.invalidateCache();" in the background

3. Tried checking the "Can Create" flag on the table

 

None of that made any difference.  So I tried putting the code in a Scheduled Job, and tried running that.  That still did not update the records.

 

Does anyone have any other ideas on how I can make these data updates quickly and efficiently (without having to edit each one manually)?  I thought about exporting the records and re-importing them, but the issue is the field I am updating is the key unique field that I would be matching on!  And I know it is a bit tricky to figure out how to export the sys_id into an Excel export.

1 ACCEPTED SOLUTION

VikMach
Mega Sage

@jmiskey, here's  a simple approach.
Follow the steps below.

 

1) First, have only one field in your list view that you wish to update with the suffix or minimum fields as possible. Like example below.

VikMach_0-1754351157166.png

 

 

2) Then click on column context menu and select "Import". Select the options as shown in the example below and click on "Create Excel template". It will process your request and show you download button. Download the template. (Don't include all fields.)

 

VikMach_0-1754353029525.png

 

 

3) This downloaded excel template will have "SysIDs" of all the filtered records along with your selected column that you chose in the list view of you custom table. See example snip below.

VikMach_3-1754351973703.png

 

 

4) Now, all that you need to do is concatenate the 2 strings as example below and upload it back with the same interface.

 

VikMach_2-1754351805279.png

 

5) Copy and paste the concatenated text to your desired column that you want to update. For example I used "Short Description" field. Do not change any field header. Otherwise it will fail.

 

VikMach_4-1754352196681.png

 

6) Save your excel and upload it back from the same interface you downloaded the template.

See example below. If all goes well no error will throw. If error shows up you can fix and upload the excel again.

 

VikMach_6-1754352401710.png

 

7) Click on "Preview imported data". Check your updates and scroll to the bottom to complete your import.

VikMach_7-1754352542605.png

 

 

VikMach_8-1754352593332.png

 

Final result...

 

VikMach_9-1754352689092.png

 

 

Hope this helps.


P.S - By the way, did you try fix script? Is it throwing the same error? Not spending too much time there. Try this little trick!

Also, did you check the scope in which you're running your script?

 

Let me know if it worked!

Regards,
Vikas K

View solution in original post

11 REPLIES 11

Shruti
Mega Sage
Mega Sage

Hi,

Navigate to System Definition-> Fix Scripts

Create a fix script in (custom table) scope application and execute the fix script

var gr = new GlideRecord('x_table_name');
gr.addQuery('active','true');
gr.query();

while(gr.next()){
	gr.security_group = gr.security_group + '- Role';
	gr.update();
}

 

Thanks.  I am out of the office for an all day meeting, but I will try a fix script tomorrow when I am back in the office.

Unfortunately, I encountered similar issues with the Fix Script attempt.  The error message was something like this: 

Script execution error: Script Identifier: unknown, Error Description: Access to GlideRecord.update from scope x_table_name not allowed, Script ES Level: 180
Evaluator.evaluateString() problem: com.glide.script.fencing.CrossScopeAccessNotAllowedException: Access to GlideRecord.update from scope x_scope_name not allowed: 	com.glide.script.fencing.ScopedScriptableObject.checkCrossScopePrivileges(ScopedScriptableObject.java:199)

(I changed the table and scope name in the error message for privacy).  Note that I did try running it from the scoped app.

 

Seeing as how the suggestion of creating the Excel template worked and did exactly what I need, I think I have an answer to my problem.  Thanks to all who replied.

t_sadahisa
Giga Guru

Hello @jmiskey 

 

How about selecting the same application scope as the table when running in “Scripts - background”?

 

Thanks.

I should have mentioned - I already tried changing to the scope to run the code, and it made no difference - I still got those errors.