
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 12-26-2019 03:48 AM
Hello,
As you might be already aware, we cannot capture the data of catalog item into the Multi row Variable set, but many times, we might have a requirement where we need to use a value of catalog item in MRVS, based on the catalog item.
In this article, i will show you how we can achieve this.
This is not the best solution, but a workaround till there is a good permanent solution found.
Here i am using sessions and putting the data of the catalog item in session and then fetching that session value in the MRVS. Using this logic, we can use the data of catalog item in MRVS and vice-versa.
In the below example, i will show you how you can pass the value of a Employee Name Field in catalog item to MRVS and prefill it when clicked on the add form.
Catalog Client Script: OnChange on Employee Name Field
Whenever a name field is changed, i want this to prefill in the MRVS Add form. So i wrote a onChange client script and storing the name field in the session.
To uniquely identify the value, i am using the sys_id of the current record.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var sys_id = g_form.getUniqueValue();
var gaSession = new GlideAjax('sessionData');
gaSession.addParam('sysparm_name','storeInSession');
gaSession.addParam('sysparm_sys_id', sys_id);
gaSession.addParam('sysparm_value', newValue);
gaSession.getXML(callback);
function callback(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
}
}
Script Include is required as GlideSession is available at the server side.
var sessionData = Class.create();
sessionData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
storeInSession: function() {
var name = this.getParameter('sysparm_sys_id') + gs.getUserID();
gs.getSession().clearClientData(name);//clear if earlier value exists.
gs.getSession().putClientData(name, this.getParameter('sysparm_value'));
return 1;
},
FetchFromSession: function() {
var name = this.getParameter('sysparm_sys_id') + gs.getUserID();
var value = gs.getSession().getClientData(name);
gs.getSession().clearClientData(name); //clearing once the value is fetched.
return value;
},
type: 'sessionData'
});
Client Script onLoad of Multi Row Variable set (MRVS) to set the value of Employee Name
function onLoad() {
//Type appropriate comment here, and begin script below
var sUrl =top.location.href;
var pos = sUrl.indexOf("sysparm_id");
pos = pos + 13; //to fetch the exact sys_id from teh URL
var sys_id = sUrl.substr(pos,32);
var gaSession = new GlideAjax('sessionData');
gaSession.addParam('sysparm_name','FetchFromSession');
gaSession.addParam('sysparm_sys_id', sys_id);
gaSession.getXML(callback);
function callback(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("emp_name", answer);
}
}
Mark the article as helpful and bookmark if you found it useful.
- 3,227 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Asif,
Above code works good for the first row, but returning a null value for second row.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Vishnu,
This article basically tells you how to pass the value of the catalog item variable which is outside of MRVS into the MRVS. If you are facing issue with the populating the data in the MRVS, check this article https://community.servicenow.com/community?id=community_article&sys_id=86971c8bdb4108106064eeb5ca961...
If you are still facing issue after that, kindly create a question with the issue and let me know. I will check and assist you.