Multiple (Array) Items in Catalog Item

phsdm
Giga Expert

I have a three part question related to design and implementation of Catalog Items.   I am often asked to design an item which accepts "one or more" items.   For example one or more (name, phone number) pairs for a request to add lines to a phone.   The reasoning behind putting multiple entries on the form is to collect related work in one request item.

 

My questions:

 

1. Is this style of request supported better some other way?

2. The way I implement this is to create variables (name01, phone01, moree01), (name02, phone02, more02) .. (name08, phone08).   Is this the standard practice?

3. I have a short attention span, and find manual creation of these variables boring and error prone.   Do tools exist to help with this?

 

I started to write some scripts to help me with this.   One to "copy" up a variable.   Increment numbers in the variable name and question, and add 50 or 100 to the order.   Another to "copy" up a UI Policy along with its actions, incrementing any references to variables.   I thought I would stop and ask these questions in case:

 

A) Doing this is pointless because I should be using alternate techniques or tools.

B) Someone already has the perfect toolkit for doing this.

10 REPLIES 10

brnunn
Tera Contributor

Hi - sorry for delay in response, didn't see the notification.



Yes, it's pretty easy to break apart the JSON string it creates. Note that the resulting json is stored in the result variable. Here is a script i use to break it apart and then rebuild it in an html table



var retstring = '';


  var json = new JSON();


  var tables = json.decode(result);


  // Result variable is an array of table objects


//iterate through tables


  for (var tIdx = 0; tIdx < tables.length; tIdx++) {


  var tableObj = tables[tIdx];



//build the first row of your table with headers:


retring += <table><tr>etc.etc.;



//iterate through table object rows:


for (var rIdx = 0; rIdx < tableRows.length; rIdx++) {


  var tableRow = tableRows[rIdx];



//for each row, iterate through all your fields


for (var fIdx = 0; fIdx < tableRow.length; fIdx++) {



  var cell = tableRow[fIdx];



//now you have access to cell['field'] and cell['value'] for label and value, respectively


}


}


}