Maik Skoddow
Tera Patron
Tera Patron
MaikSkoddow_0-1677336294596.png

 

Scoped Applications in ServiceNow are a powerful way to create secure custom applications which are completely separated from the rest of the platform. Unfortunately, this often leads to situations where certain artifacts (aka application files) have been created in the wrong scoped app (or worse: in a customized store application). Of course, you could delete such "stray" files and recreate them in the target app, but often this is not possible due to the numerous references that already exist.          
Table of Contents

The better approach would be to move the affected artifacts to another scoped application - just as it is possible between global scoped applications. Unfortunately, there is no corresponding function for this OOTB and ServiceNow itself says in the KB article KB0820186 that this is not possible. Also the answers in the community are accordingly rejecting.

 

However, via a small detour you can achieve the goal and the corresponding solution, which is presented in this article, is so trivial that I wonder if the whole thing is possibly a security risk.

 

 

 

Challenge

 

In an FSM-based implementation you have to deal with a huge amount of configurations, and schedules play a central role here, because all calculations in the "Dynamic Scheduler" are based on them.

 

FSM agents each have an individual schedule in which they can enter personal appointments. These personal schedules are not created automatically with the creation of a new user, but only when the agent wants to create the first personal appointment. And depending on the scenario, it can happen on a DEV that the personal schedules are created in a scoped app instead of in "Global" when using a test user. But once created, there is no option "Move to Application ..." available in the context menu:

MaikSkoddow_0-1677302594373.png

As a result, unwanted artifacts like these schedules are carried over to the next instance, which can cause problems.

 

 

 

Solution

 

When importing records previously exported as XML, no checks are performed and the data is imported as it is. This gives us the opportunity to manipulate the XML data before re-importing it, because the XML exports are simply text files and can therefore be edited in any text editor. And the affiliation to an application is represented in an XML export by the two XML elements <sys_package> and <sys_scope>.

 

For the above example record of a schedule, it will look like this:

MaikSkoddow_0-1677314831934.png

These two XML elements now only have to be replaced with the corresponding values of the desired application. In my example, they should be moved into the "Global" scope. Therefore the two highlighted lines in my above screenshot have to be replaced with:

 

<sys_package display_value="Global" source="global">global</sys_package>
<sys_scope display_value="Global">global</sys_scope>

 

After saving and importing the modified XML file, you might get an error like this:
MaikSkoddow_0-1677330953909.png

It took me a while finding out that in your application picker you have to choose the application your record to be moved is in currently. After selecting "Field Service Capacity and Reservations Management" the XML file could be imported without any problems and the Application columns now displays "Global" 

MaikSkoddow_1-1677331136289.png

This application file movement is not restricted to the "Global" target. I also tried successfully moving between two scoped applications!

 

With the same approach, you also can move all application files to another scoped application. To do this, go to the table "sys_metadata", select the desired application and then start an XML export. Then open the exported XML file in a text editor and use the "Find and Replace" function to perform the same replacement of the XML elements <sys_package> and <sys_scope> as before in the example with only one application file.

Comments
Uncle Rob
Kilo Patron

Holy cow!

Ishaan Shoor
Mega Sage
Mega Sage

Thanks for sharing Maik! 

surajp
Mega Guru

Nice, good trick. Building store app needs lot of modification, for example you want to move artifacts across scopes or do changes to many files. As a SN employee you get the local environment to work with the artifacts in IDE.

KevinsNewRocket
Giga Expert

This is an amazing trick! Thank you for sharing.

Jacques Clement
Kilo Sage
Kilo Sage

That’s gonna come so handy for people (like me) who keep on switching in between different scopes. I went as far as to edit the XML files as you did, but then hit the same issue you explained… and gave up. Thanks for cracking it!

Bastiaan de Zw1
Tera Guru

Thank you for sharing! 

 

Also nice with the Saxon Switzerland NP in the banner 😉

Maik Skoddow
Tera Patron
Tera Patron

@Bastiaan de Zw1 

Congrats! You are the first to realize that! 😉

Andrew Barnes -
ServiceNow Employee
ServiceNow Employee

The KB which says doing this is NOT supported, and outlines that it can be a dangerous operation. 

"is so trivial that I wonder if the whole thing is possibly a security risk." It is trivial to do many things in SN land that you should avoid but that isn't itself a security risk. In order to be powerful and flexible, some things are allowed, that you should not do, or only do in certain situations. 'I didn't notice I created the application file into the correct scope' - isn't one of those times its worth breaking the glass, and doing a dangerous operation in my experience. It won't always or maybe even frequently cause an issue, but it isn't worth the risk.

Instead focus on putting things in the right scope up front, and use the times when that is missed as a reminder to do so. 

Jon Crosby
Tera Expert

@Andrew Barnes -Re: Instead focus on putting things in the right scope up front, and use the times when that is missed as a reminder to do so. 

 
I agree, this would be ideal. 
 
But I also think ServiceNow needs to be asking itself why it has matured this far without allowing people to easily swap app scopes. In my opinion, it should have been engineered into the product when App Scope was originally added.
 
We must remember, there were a lot of apps built in Global before scoping existed and even after scoping, there was a large number of admins/devs taught by their implementors to do things in Global scope to avoid the headaches or cross scoping for years after that. Studio and App Engine Studio have clearly simplified NEW things going forward, but those old global still need a way to be modernized without a full re-write. 
 
Personally, since rolling out App Engine Studio, I usually will COPY simple (but time consuming) things into the new scope (e.g. Catalog items to avoid having to rebuild variables, ui policies, scripts and wasting time) and disable the old global. This has worked fine for me, but it's not something I would depend on for anything complex. 
Philip Green
Mega Guru

Part of the reason moving files between scopes isn't supported will likely be down to intellectual property rights of the organisation they originated from.

Robert J_
Tera Contributor

I created an idea for this topic:

https://support.servicenow.com/ideas?id=view_idea&sysparm_idea_id=6be5b3619777e91422ae35d11153af59&s...

 

Maybe in some years ( 🙂 the servicenow team will develop a solution for this challenge.

Roy Williams
Tera Contributor

Thank you for sharing! Really helpful

Ben_Barker
Giga Guru

Really great post and comments! Thank you! I also believe ServiceNow should support that « move to scope X » as Scoped Applications are and will always be evolving. The needs for easily reorganize and restructuring when major rescope happen or need to happen is pretty obvious to me.

Kevin Schultz
Tera Expert

This was incredibly helpful - thank you so much for the detailed write up! I can't believe ServiceNow makes this so infernally complicated by design, but am very thankful there's a process for the rest of us that work in the platform out here in the real world. This saved me a ton of time re-factoring some old work on our instance - so again, thank you so very much! 

Dan Covic2
Tera Contributor

It's not recommended:

 

"Once you create an app in global scope or as a scoped app, moving from one to another is not recommended. There is no tool available to automatically do this migration. You may have to basically rewrite the entire app if migration is required."

 

Source: https://www.servicenow.com/community/developer-articles/understanding-application-scope-on-the-now-p...

Kristoffer Pari
Tera Expert

Have anyone tried this with tables?

Antoni Zahariev
Tera Guru

Thanks for the great article and for documenting this @Maik Skoddow !

 

I've been comparing and fixing the XMLs in Notepadd ++ since my early days with ServiceNow 😁

 

Just to add that you could also create copies of OOTB objects and insert these into the relevant application scope by just removing the <sys_id> value.

For such cases, on top of applying the correct Application Scope and table, it will be good to delete the values for: <sys_created_by>; <sys_created_on>; <sys_mod_count>; <sys_update_name>; <sys_updated_by>; <sys_updated_on>

 

As this can be an overwhelming activity, there is the MultiReplace plugin available for Notepad ++ which helps a lot for bulk update on multiple records part of the XML extract file.

 

<sys_class_name>sys_ui_style</sys_class_name>
<sys_created_by></sys_created_by>
<sys_created_on></sys_created_on>
<sys_id></sys_id>
<sys_mod_count></sys_mod_count>
<sys_name>sn_customerservice_case</sys_name>
<sys_package display_value="Customer Service" source="sn_customerservice">51d811fad7223100b7490ee60e61034f</sys_package>
<sys_policy/>
<sys_scope display_value="Customer Service">51d811fad7223100b7490ee60e61034f</sys_scope>
<sys_update_name></sys_update_name>
<sys_updated_by></sys_updated_by>
<sys_updated_on></sys_updated_on>

 

Version history
Last update:
‎02-25-2023 07:13 AM
Updated by:
Contributors