Detecting "Update Scope Id is different than Updat... - ServiceNow Community
Mark Roethof
Tera Patron
Tera Patron

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Hi there,

 

When retrieving Update Sets on an instance, ever came across an issue concerning "Update Scope Id is different than Update Set Scope Id"? This sometimes occurs, a Customer Update being captured in your Update Set which is in a certain Application Scope, while the actual artifact being updated resides in a different Application Scope. Due to this issue, you can't commit the Update Set.

 

What can we do about this? Some ideas:
- Creating an Instance Scan Scan Check;
- Adding a validation on the Update Set concerned;
- Automatically moving the Customer Update.

 

In this article I'll focus on the second idea, applying a validation on the Update Set concerned. A validation which would show an error message when displaying the Update Set.


Update Scope Id is different than Update Set Scope Id

Here an example of the issue concerned. The issue prevents Update Sets from being committed on the target instance.

 

find_real_file.png

 

Basically, this example is about a Business Rule which is captured in an Update Set which is in the "Global" Application Scope. While the Business Rule itself, is actually in the "Service Portal - Standard Ticket" Application Scope.


Adding a validation on the Update Set

Instead of noticing this issue on the target instance, when the Update Set is already retrieved and previewed, let's add a validation on the source instance. A validation which detects if there are any Customer Updates captured in an Update Set in a different Application Scope. This will help the administrator or developer handling the Update Set, to already notice the issue before closing the Update Set.

 

My thought for this is applying a display Business Rule with a condition of "stateINin progress,complete^EQ" on table "sys_update_set", which queries if there are any Customer Updates captured in an Update Set in a different Application Scope, and if so displays an error message concerning the issues and a hyperlink to the Customer Updates concerned.

 

(function executeRule(current, previous /*null when async*/) {

    var gaCustomerUpdate = new GlideAggregate('sys_update_xml');
    gaCustomerUpdate.addEncodedQuery('update_set=' + current.getUniqueValue() + '^applicationNSAMEASupdate_set.application');
    gaCustomerUpdate.addAggregate('COUNT');
    gaCustomerUpdate._query();

    if(gaCustomerUpdate._next() && gaCustomerUpdate.getAggregate('COUNT') >= 1) {
        var plural = '';
        if(gaCustomerUpdate.getAggregate('COUNT') > 1) {
            plural = 's';
        }
  
        gs.addErrorMessage(gs.getMessage('Update Scope Id is different than Update Set Scope Id for <a href="{0}" target="_blank">{1} Customer Update{2}</a>.', ['sys_update_xml_list.do?sysparm_query=update_set%3D' + current.getUniqueValue() + '%5EapplicationNSAMEASupdate_set.application', gaCustomerUpdate.getAggregate('COUNT'), plural]));
    }

})(current, previous);

 

This will still allow the administrator or developer to change the State of the Update Set to Complete. If wanting to prevent this, we could add an onLoad Client Script which removes the "Complete" option from the choices. The Client Script, using a Scratchpad object which we would add to our Business Rule. So let's expand the Business Rule with below line:

 

g_scratchpad.scope_id_issues = true;

 

The onLoad Client Script on table "sys_update_set" would only contain the below following script:

 

function onLoad() {

    if(g_scratchpad.scope_id_issues) {
        g_form.removeOption('state', 'complete');
    }

}

 

The above Business Rule and Client Script concern the Update Set itself. Let's add a validation on the Customer Update as well. Adding a display Business Rule with a condition of "applicationNSAMEASupdate_set.application^update_set.stateINin progress,complete^EQ" on table "sys_update_xml".

 

(function executeRule(current, previous /*null when async*/) {

    gs.addErrorMessage(gs.getMessage('Update Scope Id ({0}) is different than Update Set Scope Id ({1}).', [current.getValue('application'), current.update_set.application.getValue()]));

})(current, previous);

 

Result

While reviewing the Update Set and normally changing the State to "Complete", the administrator or developer now is instantly informed about the issue. This allows the administrator or developer to fix the issue on the source instance, before even retrieving the Update Set on the target instance. This saves time, frustration, and prevents issues if you actually automated your Update Set cycle on higher instances.

 

find_real_file.png

 

In a future article, I'll share a thought on automatically moving the Customer Update, to an Update Set in the same Application Scope.


Share

An Update Set with the Business Rules and Client Script can be downloaded from Share:
- Detecting "Update Scope Id is different than Update Set Scope Id"

---


And that's it. Hope you like it. If any questions or remarks, let me know!

 

C

If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.

 

Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in?
- Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Kind regards,


Mark Roethof

ServiceNow Technical Platform Architect @ Eraneous

2x ServiceNow Developer MVP
2x ServiceNow Community MVP

---

LinkedIn

Comments
DScroggins
Kilo Sage

Great article Mark!

 

As you mentioned Instance Scan can also be used to identify mis-matched update set application scopes. This is what I use:

 

Scan Type:

Table Check

Table:

Update Set (sys_update_set)

Conditions:

State is not Ignore

Name is not Default

Script:

 

(function (engine) {

	var r = new GlideAggregate('sys_update_xml');
	r.addQuery('update_set',engine.current.sys_id);
	r.addQuery("application", "!=", engine.current.application);
	r.addAggregate('COUNT');
	r.query();
	r.next();
	
	if(r.getAggregate('COUNT') >= 1)
		engine.finding.increment();
    

})(engine);
Mark Roethof
Tera Patron
Tera Patron

Nice feedback!

Yesterday I made something similar for Instance Scan, only using the condition field though. Though same principle!

applicationNSAMEASupdate_set.application^update_set.state=in progress^update_set.is_default=false^EQ

Kind regards,
Mark

Paul Curwen
Mega Sage

This should be an OOTB capability. It is so annoying when you get caught out and easy to do when developing in the HR scope etc. Thanks for taking the time Mark, I have installed the Share Update set and hopefully it will save us some grief. 

Mark Roethof
Tera Patron
Tera Patron

Indeed, it could just be an out-of-the-box warning or some kind.

I am currently brainstorming and working on a UI Action which also fixes the issue for you.

Kind regards,
Mark

Francis Cavaciu
Mega Guru

There is a 4th option you missed.

- Fix the cause of most of these cross scope issues . . . the "click here" functionality under the following message so it automatically changes your session scope and update set - "This record is in the <scope> application, but <scope> is the current application. To edit this record click here."

I never use the "click here" due to this very issue. I'm really not sure why ServiceNow allow it to work this way out of the box, breaking their own data model.

Tim Deniston
Mega Sage
Mega Sage

ServiceNow knows of an issue with the Document Template application where all sys_update_xml records have 'Global' as their scope even though everything else about them is in Document Template. See KB0998255 in Now Support.

 

They also don't plan on fixing it. 

 

From the KB: "After carefully considering the severity and frequency of the issue, and the cost and risk of attempting a fix, it has been decided to not address this issue in any current or near future releases. We do not make this decision lightly, and we apologise for any inconvenience."

 

 

So, if you're working with the Document Template (sn_doc) scope, you'll definitely want to put in place some kind of warning system or automatic fix. 

rudipohjaniemi
Tera Contributor

Great stuff Mark! I really hate how this is not built in to the platform, your solution is a must-have for everyone.


If anyone is using Upgrade Plans, then that creates a new Application in the global scope and will trigger this warning for a huge chunk of OOB records.

So I would recommend simply adding .scope into the comparisons to avoid getting these warnings:

 

 

gaCustomerUpdate.addEncodedQuery('update_set=' + current.getUniqueValue() + '^application.scopeNSAMEASupdate_set.application.scope');

 

And same goes for the link in the errormessage. For some reason I am not allowed to post that code here.

 

 

Version history
Last update:
‎08-04-2024 05:10 AM
Updated by:
Contributors