Need to get row count when using Multi Row Variable Set before submitting the MRVS record

gaurav72
Tera Contributor

I am using Multi Row Variable Set to get multiple users and need to populate the Row variable based on the number of being entered in the variable set.

I need a way to get the count of records current present in Variable Set to set the Row variable.

For example : I already have an user selected in MRVS and when I click add again i need to get the row count so I can populate the Row field+1 of that.

Thanks 

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can observe whether it's add/removal

https://community.servicenow.com/community?id=community_question&sys_id=8a612681db8d64103daa1ea66896...

OR

you can use onLoad catalog client script and get the value of MRVS and get the count

Regards
Ankur

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can observe whether it's add/removal

https://community.servicenow.com/community?id=community_question&sys_id=8a612681db8d64103daa1ea66896...

OR

you can use onLoad catalog client script and get the value of MRVS and get the count

Regards
Ankur

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

When I am using var mrvsPIM = JSON.parse(g_form.getValue(‘name_of_mrvs’)); I am getting a SyntaxError: unexpected end of JSON input. Any advice?

patricklatella
Mega Sage

I've come up with a solution for getting the row count of entries in a multirow variable set that may help in some cases.  I created a widget that is then embedded in a catalog item that has a MRVS.  The widget creates a button that opens a popup with the row count.  Pretty simple setup and very handy in my case.

 

Steps:

- create a new widget with the following script:

 

HTML:

<div>
<button class="button-text" ng-click="c.getCount()">${Get Row Count}</button>
</div>

<!--popup modal 1-->
<script type="text/ng-template" id="modalTemplate4">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-body wrapper-xl">Total Rows is {{c.data.count}}</h4>
</div>
<div class="panel-footer text-right">
<button class="btn btn-primary" ng-click="c.closeModal()">${Close Popup}</button>
</div>
</div>
</script>

 

CLIENT SCRIPT:

api.controller=function ($scope,$uibModal) {
 
/* widget controller */
var c = this;
c.getCount = function() {
var count = $scope.page.g_form.getValue('PUT YOUR MRVS INTERNAL NAME HERE');
if(count == null || count == 'undefined' || count == ''){
c.data.count = '0';
}else{
var obj = JSON.parse(count);
var length = obj.length;
length = length.toString();
c.data.count = length;
}
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate4',
scope: $scope
});
};
c.closeModal = function() {
c.modalInstance.close();
}
}
 
- Create new Custom type variable on your catalog item that has the MRVS 
- Associate the new widget with the new variable
 
The widget creates a button that will open a popup with the row count from the MRVS.
Hope this helps someone else!