Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

mapping variable set variables to record producer

Gillerla Rajesh
Tera Contributor

Hi There,

 

i have variable set (single row) , i need to map variable set variables to record producer (target table), 

I tried this below script but it's not working,  any one help


// current.short_description = producer.Testingforpractice.sdc;
// current.description = producer.Testingforpractice.des;
// current.caller_id = producer.Testingforpractice.name;


current.short_description = producer.sdc;
current.description = producer.des;
current.caller_id = producer.name;
 
 
vice versa help me with multirow variable set also- how to map multi row variable set variable to record producer.

 

Regards,

Rajesh Gillerla.

12 REPLIES 12

HrishabhKumar
Kilo Sage

Hi @Gillerla Rajesh ,

Check this community thread which talks about how to map variable set variables : https://www.servicenow.com/community/developer-forum/mapping-multirow-variable-sets-in-record-produc...

 

You can also try this approach:

For Multi-Row Variable Set:

To map variables from a multi-row variable set, you need to iterate over the rows of the variable set and map them to the target table. Here’s an example:

  1. Define the multi-row variable set in your catalog item/record producer.
  2. Use a script to iterate through the rows and map them to the target table.

Here is a corrected script for mapping multi-row variable set variables to a record producer:

// Get the GlideRecord of the multi-row variable set table (e.g., 'u_multi_row_variable_set')
var multiRowVarSet = new GlideRecord('u_multi_row_variable_set');

// Add a query to get the relevant records if needed
multiRowVarSet.addQuery('parent', producer.sys_id);
multiRowVarSet.query();

while (multiRowVarSet.next()) {
    // Create a new record in the target table for each row in the multi-row variable set
    var targetRecord = new GlideRecord('target_table'); // Replace 'target_table' with your actual table name
    targetRecord.initialize();

    // Map the variables from the multi-row variable set to the target record fields
    targetRecord.field1 = multiRowVarSet.u_variable1; // Replace 'u_variable1' with your variable name
    targetRecord.field2 = multiRowVarSet.u_variable2; // Replace 'u_variable2' with your variable name
    // Add more fields as necessary

    // Insert the target record
    targetRecord.insert();
}

 

Thanks.

Hope it helps.

Mark it helpful and accept solution if my response was useful.

 

Thanks

hi @HrishabhKumar ,

 

it's not working

@HrishabhKumar 

This is also not working