How to auto populate project details in a multi row variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 04:15 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 04:21 AM
Hi Anand,
I have written an article on this which might help you:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 04:31 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 04:51 AM
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'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 04:58 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader