How to retrieve a variable set variable value from server script in service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 10:00 PM
Hai Team,
I am trying to access variable set variable value in server script in a widget.I am creating a UI button to repopulate the value of rejected catalog item in a new item and I was able to retrieve the values of all variables in service script of the widget .The sample code goes like this
var gr = new GlideRecord($sp.getParameter('table'));
var recordSysId = $sp.getParameter('sys_id');
data.recordExists = gr.get(recordSysId);
(using variables.variables_name I was able to get the variables values like I mentioned below)
data.varname = gr.variables.variable field_name.toString();
using this I am able to retrieve the variables value from rejected record but unable to get the variable set variable values.It is a multirow variable set.
Any suggestions please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 10:52 PM
Hello, Instead of server script access it in client script like below make sure you pass $scope as parameter in first line of your client controller which will be like below
api.controller = function($scope)
var g_form = $scope.page.g_form
c.data.mv = g_form.getValue('your mvrs internal name')
c.server.update();
In server script access it like below
Server script :
data.mvrs = input.mv;
Hope this helps
Mark my answer correct if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2022 12:38 AM
Thanks for the reply .Have already tried it but unable to retrieve the value in the client end since I have to repopulate the value again in new catalog item and I have been working on scoped application.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 11:00 PM
Multi Row variable set are stored in JSON format so you need to extract it differently
var contactArr = JSON.parse(gr.test_mvrs);
var contactCnt = gr.test_mvrs.getRowCount();
var arr = [];
if (contactCnt > 0) {
for (i = 0; i < contactCnt; i++) {
current.user = contactArr[i].user;
current.email = contactArr[i].email;
}
}