Some Common Hurdles in Scoped Apps in ServiceNow

I was recently working with one of my mentors here at Crossfuze (big shout out to Jacob Anderson for his help!) to create a new scoped app: TFS Integration application. During this process I encountered a number of limitations I had to workaround in relation to scoped apps. Here is a quick summary of things that I found:

1. Script Includes: Never assume that you can reference an OOB “ServiceNow” Script Include, always check that it is “Accessible from:” is set to “All application scopes” (should not be “This application scope only”) before trying to use it (e.g. GlideEncrypter, ImportSetUtil, GlideHTTPRequest, XMLHelper, and GlideDBObjectManager, etc.)

  • Make sure when calling Script Includes outside of your app, that you use the API Name (contains scope prefix): e.g. new global.JSON()
  • A workaround to the “GlideEncrypter” is that you can now use the following code to retrieve the un-encrypted value: “gr.element_name.getDecryptedValue()”

2. Data Imports: When importing data you can’t use the ImportSetUtil so you must create a table that extends the Import Set Row (sys_import_set_row) table in order to load the data

3. Client Scripts: You should not use the DOM directly. Here’s a list of Client side APIs that have been turned off:

  • GlideRecord – can no longer use
  • window, document, $ (Prototype), $$ (Prototype selector), $j (jQuery), $F (Sizzle) – can only use them if you set the property below
  • All APIs above (except GlideRecord) can be re-enabled on a per-application basis. To do so, you need to set a True/False system property in your application named glide.script.block.client.globals with the value false

4. Server methods: Cant directly use methods such as “indexOf, toUpperCase, split…” functions, you must first convert the element “toString()” before using them (or use ArrayUtil if applicable).

5. Business Rules: You cannot use “Query” Business Rules

6. Client Scripts: You can only use the following g_form methods in the same scope as the calling script (don’t try using them on fields you didnt create in your app): “setReadOnly, setMandatory, setDisabled, setDisplay”

7. Long Running Transactions: Be aware of long-running queries (break your pulls/loads into “chunks”), if something in your apps runs longer than 10 minutes it will be killed based on the “Scoped Background Transactions” quota rule. Note that ServiceNow can override this on a per case basis.

8. Client Scripts: No longer can use “Global” Client Scripts within Client Scripts. Now must use UI Scripts for these (makes sense). Previously, if you wrote your own functions outside of the ServiceNow client script (e.g. outside the onChange/onLoad…), then that function was available to other client scripts as it was in the “global” context. That is no longer the case.

9. Forms: Can’t change forms or dictionary values of fields that are not in your scope
10. Fields: You cannot add new fields to the sys_user_group table

 

Have more issues you’ve found that I didn’t mention (very likely), please share them in the comments!

For more details please see the following links:
http://wiki.servicenow.com/index.php?title=Scoped_System_API#gsc.tab=0
https://community.servicenow.com/community/develop/blog/2015/10/01/scoped-applications-and-client-scripts-a-primer
https://community.servicenow.com/community/develop/blog/2016/05/25/client-side-gliderecord-replacement-for-scoped-applications
https://community.servicenow.com/message/848970#848970
https://community.servicenow.com/message/778501#778501
https://community.servicenow.com/message/927530#927530

Leave a Reply

Your email address will not be published. Required fields are marked *