hrng
Giga Expert

Hi All,

I recently had the displeasure of figuring out how the heck the new multi-row variable sets work, and how to mash the data into a record producer script to get something useful on the other side. There doesn't seem to be much (if any) documentation on this, so a lot of trial and error discovered the following:

  • Printing the variable (in my case 'producer.contact_details') outputs something that looks like an array of objects
  • The typeof this variable is an object, so .length and forEach won't run on it
  • The individual objects within the collection can be accessed through IDs, e.g. 'producer.contact_details[0].email', however printing just 'producer.contact_details[0]' returns null.
  • There are a number of undocumented methods on the object, discovered through a 'help' method (producer.contact_details.help()):
****************************************************************************************************
Class: com.glide.catalog.component.variables.runtime.models.table.impl.TableVariableNode
----------------------------------------------------------------------------------------------------
 Interface: com.glide.catalog.component.variables.models.table.api.ITableVariableNode
----------------------------------------------------------------------------------------------------
  void deleteRow(int)
  com.glide.catalog.component.variables.models.table.api.ITableVariableRowNode addRow()
  java.util.Set getQuestionIds()
  com.glide.catalog.component.variables.models.table.api.ITableVariableRowNode getRow(int)
  int getRowCount()
  java.util.List getRows()
  com.glide.catalog.component.variables.models.table.api.ITableVariableCellNode[] getCells(java.lang.String)
====================================================================================================
Property Based Accessors/Mutators
  Default Getter: com.glide.catalog.component.variables.models.table.api.ITableVariableCellNode[] getCells(java.lang.String)
  Default Setter: void setCellValues(java.lang.String,java.lang.Object)
  Default Setter: void setRows(java.lang.Object)

****************************************************************************************************
  • I couldn't get much out of the getRow/getRows and getCells methods, but getRowCount thankfully did return an accurate count of rows.

So the end result of all this is the following to add your rows to the comments of a newly created incident:

var commentTmp = '[code]<p>Customer has requested the following new contacts:</p>';
var contactArr = producer.contact_details;
var contactCnt = producer.contact_details.getRowCount();
if (contactCnt > 0) {
	for (i = 0; i < contactCnt; i++) {
		commentTmp += '<p><b>Name:</b> '+contactArr[i].user_name+
		'<br><b>Email:</b> '+contactArr[i].email+
		'<br><b>Mobile:</b> '+contactArr[i].phone_mob+
		'<br><b>Direct:</b> '+contactArr[i].phone_office+
		'<br><b>Type:</b> '+contactArr[i].type+'</p><br>';			
	}
	commentTmp += '[/code]';
}
current.comments = commentTmp;

I'm sure there's a much neater way to do this, but through brute force this is the best I could find, and hoping it helps someone else in a similar situation.

If anyone knows of a place where documentation for this is hidden away, I'd greatly appreciate it!

Comments
hrng
Giga Expert

Stumbled across the documentation for this by accident today: https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/concept/c_ScriptableServiceCatalogVariables.html

Not sure why that wasn't showing up on my previous searches, but would've saved a lot of time. 🙂

So seems the "official" method to use here would be to iterate over each row with a .getRow call, then access the variables on that. I'm not sure why that would be needed over the method I've used above unless you needed to set values on the row, but worth noting.

What would be useful is a .toArray method of some sort, to allow the array of objects to be iterated over and massaged in native JS.

TrenaFritsche
Tera Expert

I am looking for ways to work with this type of variable from the client script catalog item?  Anyone have any examples or documentation of scripting and how to view the values in the variables of a multi-row variable set?

 

Thanks,

Trena

Tamoghna
Kilo Contributor

Hi Trena,

 

I have similar requirement to access multirow added rows in catalog client script.

Please let me know if you were able to achieve it?

 

Thanks in advance!

nichoffman
Kilo Expert

Hi TrenaFritsche,

I'm trying to acheave the same thing. Have you found any solution?

TrenaFritsche
Tera Expert

Hi Tamoghna,

At the point in time that I asked the question, I didn't get a solution that would have worked in my scenario, so I chose to redesign how I was using it based on various replies.  (I subscribed to the topic and receive lots of emails when someone posts on this topic).  As time goes by, the solution will most likely get posted, I'd keep checking!

Thanks,

Trena

 

TrenaFritsche
Tera Expert

Hi nichoffman,

Please see my response above to Tamoghna.  Basically, I just stopped waiting for a solution and changed what was implemented.

Thanks,

Trena

 

hollysnyder
Mega Guru

Hi hrng,

I am currently trying to capture the values from my MRVS and display them in the Description field on an HR Case. However, using your script above, I get a "Function getRowCount is not allowed in scope sn_hr_core." Any suggestions on ways around this?

Thank you for any assistance you can provide!!

 

hrng
Giga Expert

Not sure sorry - haven't had to play with this in scoped apps. You could try printing out the .help() function on that variable, see what it spits out.

Duodecimal
Mega Guru

I managed to script this last week and decided to share the wealth in an article.

Uncle Rob
Kilo Patron

I've had multi-million dollar use cases for this sitting on the shelf for half a decade or more.
I'm more than a little depressed with the UX and dev accessibility of this feature.

Anthony78
Kilo Sage

Hi Hrng,

I have tried with your script and got email,phone num details but not able to get name. it's  just showing sys_id, i tried to give contactArr[i].user_name.getDisplayValue() but result came as unavailable.

Version history
Last update:
‎10-21-2018 07:56 PM
Updated by: