
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2014 02:26 PM
I need to use the same client side script in both a UI action and a UI policy. I'm wondering if it's more efficient to use a script include, or to just type the code twice in both places. My gut says the former, but I can't get my script include and glide ajax to work to return the code. The code is just g_form.setMandatory('variables.cat_variable', true); for about 5 variables. In this code, i'm only showing 2 for example. Thoughts?
Script include example:
Client checkbox is true
var MandatoryFields = Class.create(); MandatoryFields.prototype = Object.extendsObject(AbstractAjaxProcessor, { mandatoryFields: function(){ return "g_form.setMandatory('variables.example1', true); g_form.setMandatory('variables.example2', true);"; }, });
Client side UI action & UI Policy (Run scripts = true)
var ga = new GlideAjax('MandatoryFields'); ga.addParam('sysparm_name','mandatoryFields'); ga.getXML(EnforceMandatoryFields); function EnforceMandatoryFields(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); }
Note: The business case for this is certain catalog variables need to be filled out before the user can close a specific catalog task.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2014 06:26 PM
Here's what you can do to "share" code:
1. create an onLoad Client Script with the code that you want to run from the UI Action and Policy:
function onLoad() {
}
function u_setMandatoryFields() {
g_form.setMandatory('variables.example1', true);
g_form.setMandatory('variables.example2', true);
}
The onLoad function does nothing at all, but it allows the u_setMandatoryFields function to be defined.
2. Now you can call u_setMandatoryFields() from both places.
GlideAjax is used when you want to actually return values for use somewhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2014 06:26 PM
Here's what you can do to "share" code:
1. create an onLoad Client Script with the code that you want to run from the UI Action and Policy:
function onLoad() {
}
function u_setMandatoryFields() {
g_form.setMandatory('variables.example1', true);
g_form.setMandatory('variables.example2', true);
}
The onLoad function does nothing at all, but it allows the u_setMandatoryFields function to be defined.
2. Now you can call u_setMandatoryFields() from both places.
GlideAjax is used when you want to actually return values for use somewhere.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2014 09:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2014 09:45 AM
You are welcome.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2014 11:42 PM