Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How will i get the row count of multi variable set using onsubmit catalog client script

ServicenowDev19
Tera Contributor

logivention_0-1679737517186.png

I have 2 feilds in multi row variable set.I want to fetch the row count of tat variable set on submit of the multi row variable and display the row **bleep** in alert.

please guide me for this.

1 件の受理された解決策

@ServicenowDev19 ,

 

You need to create this onsubmit client script on catalog item (Not on variable set client scripts) as mentioned below:

 

PRINCE_ARORA_0-1679757403973.png

 

元の投稿で解決策を見る

9件の返信9

Ratnakar7
Mega Sage

Hi @ServicenowDev19 ,

 

You can use the following code:

 

function onSubmit() {
  // Get the variable set using its sys_id
  var variableSetSysId = g_form.getControl('variable_set').value;
  var gr = new GlideRecord('item_option_new');
  gr.addQuery('variable_set', variableSetSysId);
  gr.query();

  // Get the number of rows in the variable set
  var rowCount = 0;
  while (gr.next()) {
    rowCount++;
  }

  // Display the row count in an alert
  alert('Number of rows: ' + rowCount);
  
  // Return true to continue with form submission
  return true;
}

 

 

If my response helps you to resolve the issue close the question by Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.

 

Thanks,

Ratnakar

 

Hiii Ratnakar i am geeting row count , i want the record count.

Plz guide me for this.

 

ServicenowDev19
Tera Contributor

Hii Ratnakar,

I am getting the row count , i want the record count .How to do that?

 

Prince Arora
Tera Sage

@ServicenowDev19 ,

 

If you want to check number of rows in the MVRS, here is the script:

 

var mvrsData = g_form.getValue('mvrs_internal_name'); //backend name of mvrs
var obj = JSON.parse(mvrsData);
var length = obj.length;

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.