How do I configure the dependent choices from the actual form in Record Producer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 08:44 AM
I need to configure the dependent choices from the actual form in Record Producer?
I have successfully performed the function in agent view:
When Category = Change, only show Subcategories = Modify or New Feature
When Category = Demo, only show Subcategories = Demo or New Project
But I can't do the same function in Record Producer view:
In Studio i try to edit the FORM and get the following help comment:
"Configure Dependent Choices from the Actual Form".
How can i perform the same in Studio / Record Producer?
thanks
- Labels:
-
Instance Configuration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 09:11 AM
Hi
I think you will need an onChange catalog client script, like so (change field names like category and sub category to match your needs):
type: on change
catalog item: <your catalog item>
variable name: category
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
if(newValue == '') {
g_form.getControl('u_snr_subcategory').options.length = 1;
return;
}
//Get Category Type
var category = g_form.getValue('category');
var ga = new GlideAjax('AJAXGetSysChoices'); //script include name
ga.addParam('sysparm_name','get'); //function called in script include
ga.addParam('sysparm_table',"<YOUR_TABLE_NAME>");
ga.addParam('sysparm_element',"u_snr_subcategory");
ga.addParam('sysparm_dependent_value', category);
ga.getXML(evaluateChoices);
}
function evaluateChoices(response) {
g_form.getControl('u_snr_subcategory').options.length = 1;
var choices = response.responseXML.getElementsByTagName("choice");
for(var i = 0; i < choices.length; i++)
g_form.addOption('u_snr_subcategory', choices[i].getAttribute("value"), choices[i].getAttribute("label"));
}
script include:
name: AJAXGetSysChoices
client callable: true
script:
var AJAXGetSysChoices = Class.create();
AJAXGetSysChoices.prototype = Object.extendsObject(AbstractAjaxProcessor, {
/* Returns the selected sys_choices
sysparm_table: table name
sysparm_element: element name
sysparm_dependent_value: dependent value */
get: function() {
var gr = new GlideRecord('sys_choice');
gr.addQuery('name', this.getParameter('sysparm_table'));
gr.addQuery('element', this.getParameter('sysparm_element'));
gr.addQuery('dependent_value', this.getParameter('sysparm_dependent_value'));
gr.query();
while(gr.next())
this._addChoice(gr.label, gr.value);
},
_addChoice: function(label, value) {
var choice = this.newItem("choice");
choice.setAttribute("label", label);
choice.setAttribute("value", value);
}
});
Note that in the service portal you will have to add the options manually using an onchange catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
if(newValue == '98f4f07bfd4911007c54d659c08a79c2') { //the category you need
g_form.clearOptions('u_snr_subcategory');
g_form.addOption('u_snr_subcategory', 0, '');//nothing
g_form.addOption('u_snr_subcategory', <option value>, 'option one');
g_form.addOption('u_snr_subcategory', option value>, 'option two');
g_form.addOption('u_snr_subcategory', <option value>, 'option three');
}
}
etc.
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 09:46 AM
Hello Tony,
Below onChange Client script helps you out