How do I configure the dependent choices from the actual form in Record Producer?

Tony98
Mega Expert

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

find_real_file.png

But I can't do the same function in Record Producer view:

find_real_file.png

 

 

 

find_real_file.png

In Studio i try to edit the FORM and get the following help comment:

"Configure Dependent Choices from the Actual Form".

find_real_file.png

How can i perform the same in Studio / Record Producer?

thanks

 

2 REPLIES 2

oharel
Kilo Sage

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

ar1
Kilo Sage

Hello Tony,

 

Below onChange  Client script helps you out

 

script:

 

function onChange(control, oldValue, newValue, isLoading) {

// if (isLoading || newValue == '') {
// return;
// }


g_form.clearOptions('subCat');

g_form.addOption('subCat','','--None--');

var category = g_form.getDisplayValue('u_type');


if(category == 'Change')
{
g_form.addOption('subCat','u_modify','Modify');
g_form.addOption('subCat','new_feature','New Feature');

}

if(category == 'Demo')
{
g_form.addOption('subCat','u_demo','Demo');

g_form.addOption('subCat','new_project','New Project');

}
}