How to auto populate project details in a multi row variable set

AnandKumar1
Tera Expert

Hi Team,

I have a requirement to auto populate the number of projects involved by a specific user. For this i have used a Multi row Variable set. I have a variable referring to Project table inside variable set.

In case if the logged user is assigned to 2 projects, I need to show two rows with the project details in the Multi row variable set automatically on load of that catalog item.

Can you please help to achieve this.

 

Thanks in advance.

 

6 REPLIES 6

Willem
Giga Sage
Giga Sage

Hi Anand,

 

I have written an article on this which might help you:

https://community.servicenow.com/community?id=community_article&sys_id=f911162e1b6e1054d2ccea89bd4bc...

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

You should use this approach

1) create onLoad catalog client script

2) Create Script include and use GlideAjax to determine the projects for the logged in user

3) form a json string and return it from the function

4) then assign the json string to that MRVS variable

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

Thanks for your reply. I have created script include. can you please help little more how to use this ajax in catalog client script. Pasting my script include here.. 

Note: I have used OOB asset table instead of project table for security reasons.

Script Include:

var getAssetDetails = Class.create();
getAssetDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getDetails: function(){

var asset = this.getParameter('sysparm_asset');
var gr = new GlideRecord('alm_asset');
gr.addQuery('aaset_tag',asset);
gr.query();
if(gr.next()){
var ar=[];
ar.push(gr.getValue('serial_number'));
ar.push(gr.getValue('model_category'));
ar.push(gr.getDisplayValue('location'));
//ar.push(gr.getValue('location'));
ar.push(gr.getValue('display_name'));


}
return JSON.stringify(ar);

},

type: 'getAssetDetails'
});

 

Hi,

updated script include below

I assume your MRVS variable names are as below and are of type string

serial_number, model_category, location, display_name

var getAssetDetails = Class.create();
getAssetDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getDetails: function(){

var arr = [];

var asset = this.getParameter('sysparm_asset');
var gr = new GlideRecord('alm_asset');
gr.addQuery('aaset_tag',asset);
gr.query();
if(gr.next()){

var obj = {};
obj["serial_number"] = gr.getValue('serial_number');
obj["model_category"] = gr.getValue('model_category');
obj["location"] = gr.getDisplayValue('location');
obj["display_name"] = gr.getValue('display_name');
arr.push(obj);

}
return JSON.stringify(arr);

},

type: 'getAssetDetails'
});

At client script just use this

g_form.setValue('mrvs_variableName', answer);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader