How to access Multi-row variable set using Scripts.


Will try to explain with an example

  • Here is a list of Multi-Row Variable sets
    https://<INSTANCE NAME>

  • Once a RITM is submitted, we do see the variables with its values are stored in a table - sc_multi_row_question_answer 
  • Please see the docs for more info

  • In the docs, table_var means we should provide the name of the Multi-Row variable's which is Internal Name 

  • Below is the sample script that can be used to access the variables

    • We have a multi-row variable with the name as "server_build_list" and defined with the following fields  are below [with data type] 

      u_data_center  - Reference 
      u_how_many - Integer
      u_storage_size - reference

    • Script to access the same is below

      var gr = new GlideRecord('sc_req_item'); 
      if (gr.get('<SYS_ID OF RITM>')) 

      // Syntax for this is gr.variables.table_var which returns JSON array value as String
      gs.log( "1.variables "+ gr.variables.server_build_list);

      // Syntax for this is gr.variables.table_var.getRow(<ROW NUMBER [i]>) which returns ith row from the multi row variable

      // and we are trying to access a cell out of it as below

      var row = gr.variables.server_build_list.getRow('1');
      gs.log( "Fetching Row 1 "+ row.u_data_center);

      // Syntax for this is gr.variables.table_var.getRowCount( ) which returns current row count
      gs.log( "Row Count "+gr.variables.server_build_list.getRowCount());

    • Result

      *** Script: 1.variables [ { 
      "u_data_center" : "a41d652bdb335b00af053b2ffe9619e0", 
      "u_how_many" : "1",  
      "u_storage_size" : "1024" 
      }, { 
      "u_data_center" : "a41d652bdb335b00af053b2ffe9619e0", 
      "u_how_many" : "4", 
      "u_storage_size" : "2048" 
      } ] 

      *** Script: Fetching Row 1 a41d652bdb335b00af053b2ffe9619e0
      *** Script: Row Count 2 


Applicable Versions

London and above

Article Information

Last Updated:2019-05-21 11:54:27