Populate the Select Box in Multi-row Variable set dynamically

up1296
Kilo Explorer

Hi,

I have created a catalog item with Multi-row Variable Set. Multi-row variable set has a select box which needs to be populated dynamically. One of this values should be populated based on the variable on catalog item.

Example

Team Name : ABC   <-- Team Name is a single-line text variable on Catalog Item 

Role (variable of type select-box in multi-row variable set) - it should have below values

1. Admin (this value can be hard-coded)

2. End-user (this value can be hard-coded)

3. ABC Team <- Team Name(variable on catalog item)+'Team' ** should be populated dynamically in MRVS based on variable of catalog item

Please suggest

3 REPLIES 3

Ravali G
Kilo Expert

Hi,

Find the below Script. It works.

Write an OnChange client script as below. Select the variable Team Name in the variable name field

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var val=newValue+' team';
g_form.addOption('role',val,val);

}

Hope this helps. Please hit helpful and mark question as correct if it works fine.

Hi,

 

I tried it, but no luck. Project name is a catalog item variable and Role is Multi-row variable set variable, may be this is causing issue. 

Ravali G
Kilo Expert

Hi,

Find this updated script. Hope this works.

OnChange Client script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var val1=g_form.getValue('team_name');
var ajax = new GlideAjax('mrvs');
ajax.addParam('sysparm_name','addChoice');
ajax.addParam('sysparm_team',val1);
ajax.getXML(createout);

function createout(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage(answer);
}
}

 

Script include:

var mrvs = Class.create();
mrvs.prototype = Object.extendsObject(AbstractAjaxProcessor, {
addChoice:function(){
var gr=new GlideRecord('question_choice');
gr.addQuery('question','885b6776db8a3b40df139a64db9619bd');//sys-id of Role variable

gr.orderBy('sys_created_on');
gr.chooseWindow(2,3);//Depends on no of variables you have
gr.query();
gr.next();
gr.deleteRecord();

var add=this.getParameter('sysparm_team')+' team';
gr.initialize();
gr.question='885b6776db8a3b40df139a64db9619bd';//sys_id of Role variable;
gr.text=add;
gr.value=add;
gr.order='300';//Depends on no of variables you have
gr.insert();
return 'hi';
},
type: 'mrvs'
});

Hope this helps. Please hit helpful and mark question as correct if it works fine.