Domain override via script

davidmcdonald
Kilo Guru

With domain separated records with overrides, I know that the overrides are obeyed using glideRecord.element.getRefRecord() (e.g. for a workflow or UI policy),

but is it possible to do so as part of a GlideQuery?

E.g. using gr.get(some_sys_id) to ultimately return the nearest domain override for a domain.

1 ACCEPTED SOLUTION

davidmcdonald
Kilo Guru

I've been able to get around the issue by walking down the sys_overrides chain (A overrides B overrides C), and checking domain visibility every step along the way.



It's not efficient but it does the trick. I'll try to neaten it up and provide it later.



Ideally, I'd love to know how ServiceNow does it natively like how it does with reference fields.



Top tip: Name all of the overrides the same for ease of querying (just query the same name, adding addDomainQuery for the target domain).


View solution in original post

7 REPLIES 7

Jim Coyne
Kilo Patron

I think queryNoDomain() will do what you are looking for.


Afraid that queryNoDomain() just removes any domain separation from the query, I'm after a way to return the final result after all overrides are applied.


The SN Nerd
Giga Sage
Giga Sage

This should be what you are looking for:



http://wiki.servicenow.com/index.php?title=GlideRecord#addDomainQuery&gsc.tab=0



An example is provided on the wiki page.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

The SN Nerd
Giga Sage
Giga Sage

Does the wiki example not solve this problem?



var domain = new GlideRecord('sys_user');


domain.addQuery('user_name', 'itil');


domain.queryNoDomain();


if (domain.next()) {


    var domainQuery = new GlideRecord('incident');


  domainQuery.addQuery('active', true);


  domainQuery.addDomainQuery(domain);


  domainQuery.query();


  gs.print('Number of Incidents for ITIL user: ' + domainQuery.getRowCount());


    while (domainQuery.next())


  gs.print(domainQuery.number);


}



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022