Copy multi-row variable set to another task

Shawn Dowler
Tera Guru

In London and Madrid I can create multi-row variable sets and get them to display in the formatter for the submitted record using a record producer. I want to be able to copy the variable set to another task. I can do this using the question_answer table, but the variables don't get formatted like a multi-row variable set. I tried also creating records in the sc_multi_row_question_answer table and it doesn't seem to make a different. The Row index field can't be the only thing, because I tried creating a record using a record producer that rendered the multi-row variable set correctly, duplicating the records and deleting the old ones and it still would render my new variables as a table.

Any missing pieces in this equation? I couldn't find any other tables that might be involved or fields on the question_answer table or sc_multi_row_question_answer table.

Thanks!

1 ACCEPTED SOLUTION

H_kon Sm_rvik
Kilo Expert

I might have found the missing piece!

You need to create a record in the table sc_item_produced_record. The formatting seems to be correct as well.

In my code I added this snipppet. This piece is targeted at a single catalog item, and towards the change_request table. It should be easy enough to modify this to accomodate other producers and tables.

function createProducedRecord(change_id) {
  var producer = new GlideRecord("sc_cat_item");
  producer.addQuery("name", "<name of record producer / cat_item>");
  producer.query();
  
  if (producer.next()) {
    var produced_record = new GlideRecord("sc_item_produced_record");
    produced_record.initialize();
    produced_record.record_table = "change_request";
    produced_record.task = change_id;
    produced_record.record_key = change_id;
    produced_record.producer = producer.getUniqueValue();
    produced_record.insert();
  }
}

View solution in original post

5 REPLIES 5

Jace Benson
Mega Sage

Can you include some reproduction steps so I can look into this?

jluisangelgtz
Tera Contributor

Hi Shanwn,

Have you found a solution for this?

Jacebenson, 

I think Shawn and I have the same requirement, so the steps would be:

 

 

1.- We have a record created from a record producer

 find_real_file.png

2.- from a script in a UI action or business rule we want to copy that record including the variables. some of those variables are multi-row variable sets.

To copy variables from one record to another you can you use the script from this other post

https://community.servicenow.com/community?id=community_question&sys_id=c5440f29dbd8dbc01dcaf3231f961942

what this script does is insert a record with a GlideRecord and then create an instance of each variable in the table "question_answer"

3.- when you execute that UI action it works fine for variables on the record producer but it does not work for variable sets or multi-row variable sets. The variables in the variable sets are not copied into the new record

 find_real_file.png


4.- if you look at the instances in the table "question_answer" for a record that was created from a record producer you can see that there's an instance for the multi-row variable set and in the table "sc_multi_row_question_answer", there is an instance for each variable in the multi-row variable set.

 find_real_file.png

 

find_real_file.png 


5.- if you modify the script to include also the instance for the variable sets in the table "question_answer" and the instances for variables in the multi-row variable set in the table "sc_multi_row_question_answer", the variables are displayed in the new record but they are not rendered as a table variable set

 find_real_file.png

So it seems, there's another table that we haven't been able to find where we need to create an instance to correlate the record and the record producer, I also tried to use the table "sc_item_produced_record" but it didn't work neither

jcoss
Giga Expert

Hi,

I'm having the same issue, were you able to find a solution? 

Thanks,

H_kon Sm_rvik
Kilo Expert

I might have found the missing piece!

You need to create a record in the table sc_item_produced_record. The formatting seems to be correct as well.

In my code I added this snipppet. This piece is targeted at a single catalog item, and towards the change_request table. It should be easy enough to modify this to accomodate other producers and tables.

function createProducedRecord(change_id) {
  var producer = new GlideRecord("sc_cat_item");
  producer.addQuery("name", "<name of record producer / cat_item>");
  producer.query();
  
  if (producer.next()) {
    var produced_record = new GlideRecord("sc_item_produced_record");
    produced_record.initialize();
    produced_record.record_table = "change_request";
    produced_record.task = change_id;
    produced_record.record_key = change_id;
    produced_record.producer = producer.getUniqueValue();
    produced_record.insert();
  }
}