The CreatorCon Call for Content is officially open! Get started here.

Update reference qualifiers via script

kchorny
Tera Guru

We are faced with this issue: in catalog items, it is sometimes necessary for the end user to select a user that is no longer active (for example, request to access the users data after they've already left the company). However, OOB ServiceNow does not allow end users to have visibility to inactive users so when asked to select the user whose data they need access to, they can't find them.* I've fixed that issue, but now I need to update the reference qualifier for all fields pointing to the user table (~5500) and add 'active=true'. 

 

I've written this script to update one record to see what happens, but it doesn't make the change and I'm wondering what I'm missing.

 

 

var refqual = 'active=true';
var qs = 'use_reference_qualifier=simple^reference=sys_user^reference_qual_conditionNOT LIKEactive=true^ORreference_qual_conditionISEMPTY';
var d = new GlideRecord('sys_dictionary');
d.addEncodedQuery(qs);
d.query();
gs.print(d.getRowCount());
if (d.next()) {
	if (d.reference_qual_condition != '') {
		refqual = refqual + '^' + d.reference_qual_condition;
	} 
	gs.print(d.element);
	gs.print(d.name);
	d.reference_qual_condition = refqual;
	d.reference_qual = refqual;
	d.autoSysFields(false);
	d.update();
}

 

 

 

16 REPLIES 16

It's set to "if" instead of "while" until I can verify that the script works. 😉

To be honest, updating the dictionary record is not a good idea. It can mess things up if went wrong.

I would have updated the the catalog item to give user option to enter the user id of the user in a string field if the user not found and map it automatically via script on submission.


Please mark this response as correct or helpful if it assisted you with your question.

I would be updating the dictionary record if I added the filter manually as well, correct? In any case, with this solution we are also addressing other requests to have visibility to inactive users outside of the service catalog, which in turn would require the active filter be applied to the fields to keep those users from selecting inactive records.

No. You just make changes to the catalog and not make any changes to the onBefore Query business rule on user table. So you wont need any update to the dictionary record. 


Please mark this response as correct or helpful if it assisted you with your question.

OlaN
Giga Sage
Giga Sage

Hi,

The specific reason for why this isn't working is because the reference_qual_conditions isn't a String field.

It's a Conditions field, so you can't script it's contents in this manner.

 

And another pointer/question.

In your question you describe that the issue is within the Service Catalog, by that it sounds like you would want to update some or all Catalog variables [item_option_new] that point on the sys_user table, but in the script you are targeting the [sys_dictionary] table. Is this a mistake?