Override Variable Set Default Value in Catalog Item

jmiskey
Kilo Sage

We use the Service Portal quite heavily.  We have a lot of Catalog Items on it.  For efficiency sake, we have a Variable Set that we use in the majority of our Catalog Items that returns a bunch of information about the Requestor and their Manager.  In this variable set, the "requested_for" field has the default value of:

javascript: gs.getUserID();

so it defaults to the person filling out the sheet , and then there are Catalog Client Scripts to populate all the related information about the user and their manager.

We have a "New Hire Onboarding" form that uses this Variable Set, but the issue is that a user would NEVER be filling out their own "New Hire Onboarding" form (as matter as fact, I need to ensure that the requestor CANNOT choose themself, which I can do with some Catalog Client Scripts).

So, what I really want to do is to "override" the default in the Variable Set.  But here is the tricky part -- I need to do this without making any changes to the Variable Set (under strict order from boss not to mess with that).  So, I need to do it using Catalog Client Scripts from the "New Hire Onboarding" Catalog Item.  

I was able to add code to clear the "requested_for" value, but it appears that runs AFTER the default is applied, so it left all the related User and Manager information populated, even though the "requested_for" value was cleared.  I think what I need to figure out is how to override the "default", so it is never applied in the first place, so those other related fields do not get an initial population based on the default value.

Does anyone have any good ideas on how to best accomplish this (without trying to write a whole bunch of code to undo everything)?

Thanks

 

10 REPLIES 10

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I don't think you'll be able to prevent the default value from being applied in your update set variable. If it were me I would disassociate that variable set with the catalog item and create variables specific to this catalog item. If you're not able to do that you would probably need to add to your script so that the related variables are cleared out or populated with the correct information.

That is what I was afraid of.  They want me to use that Variable Set, but not change it - to control everything from Catalog Clients Scripts on the Catalog Item.

This issue that I am having is I can get it to the Catalog Client Scripts from the Catalog Item to override the Catalog Client Scripts from the Variable.  I can get everything to start out blank, which is great.  The issue I am having is if they select themselves.  I have a Catalog Client Script in the Catalog Item which clears out the requested_for field, but I cannot get it to clear out the related fields. 

There is some interference I cannot quite figure out yet.

If I cannot figure it out, I may have to try to convince my boss to create a separate variable set for this one.

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Curious about this one, I tried to reproduce this. Though, while overriding the variable (on the variable set) thru a catalog client script on the catalog item, it looks like the default value + the onchange filling of other variables is overwritten. Is this what you are also after? Or did I misunderstood your question?

Without overwrite:

find_real_file.png

With overwrite:

find_real_file.png

Basic onLoad Catalog Client Script on the Catalog Item:

find_real_file.png

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

I already have code that looks very similar to that, and that part works fine.  The issue is that there are Catalog Client Scripts running one the Variable Set that are populating the related fields, and when I try to select myself as the user, my code immediately clears out the requested_for field, but not all the related fields (it populates them with information about me). 

So, the flow appears to be something like this:

1.  I choose myself

2.  It populates all the related fields about myself

3.  It removes me from the requested_for field, but not any of the related fields

I even tried added explicit commands to clear the values out of the other fields (under the one that clears it out of the requested_for field), but that didn't even work.  Try as I might, I cannot get it to clear out the requested_for fields when I try to select myself under the requested_for field.