Catalog Task onChange Client Script for Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2013 02:24 PM
Is it possible to create on onChange client script for a variable included on a Catalog Task?
On a request form I have 3 variables (Assignment Group, Department, and Computer Type) which depend on each other to determine if billing is required when a request item is initially submitted. After the initial submission a technician may find information (such as computer type) was incorrectly entered, and they modify it in the task variable editor. This change may have an impact on the billing requirements, but there is no way I can think of to test for it.
I can't seem to create an onChange client script to monitor anything in the variable editor. I've also tried it with a UI policy, but it only works when the Assignment Group field is changed which is not a variable on the Catalog Task. I've even tried adding another event handler even though the Wiki says, "you are strongly discouraged from using this technique to set onSubmit(), onLoad(), or onChange() handlers. Doing so will have the effect of overriding our out-of-box handlers." I was just curious if it would work. It did not. The script always returned "undefined" for the control of the variable when trying:
var control = g_form.getControl('variables.compType');
alert("Control = " + control);
So the additional event handler had no effect.
I was basically able to accomplish what I need by using an onSubmit script. This allowed me to query the values of the necessary variables in the variable editor, so the script could determine the billing requirements. Unfortunately this is really inefficient because the individual updating the ticket will not know the billing requirements before they try to submit. Having literally hundreds of combinations to determine the requirements makes an onChange script basically a necessity.
I've spent a couple of days on this now, so I'm hoping someone may be able to point me in the right direction.
Thanks in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2013 07:23 AM
You should be able to get the control for a variable on the catalog task with the following, by putting the code in an onLoad client script:
var ctrl = g_sc_form.getControl('variableName');
I'm not sure what your Calgary upgrade plans are, but running client scripts and ui policies on requested item and catalog task variables gets a lot easier in Calgary as you can set your catalog client scripts and ui policies to run on those forms as well as the catalog item order form. You might explore that route before creating some complex sc_task client scripts.
http://wiki.servicenow.com/index.php?title=Creating_a_Catalog_Client_Script#Creating_a_Catalog_Client_Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2013 10:52 AM
Thank you b-rad! First, maybe I've been living under a rock, but I've never used or seen g_sc_form before. Second, you're right it sounds like the upgrade to Calgary will make this job much easier.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2013 11:54 AM
Hey Jevans,
Did you ever get this figured out?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2013 02:23 PM
var control = g_form.getControl('ni.VE8254310d6f2485004992e811af3ee4d0');
Works like a charm in Berlin for me; just copied the inner HTML from the DOM for the variable I needed.
-Subash Biswas