How to insert MRV in open ticket with script

Natan Felipe
Tera Expert
Hi everyone!
I need help with a question
, how to add MRV to an existing ticket?
 
I need it to stay in this format
01.png
 
But when I try to insert it it stays in this format
02.png
I'm using background script to build the solution because I need to run code for this

 

1 ACCEPTED SOLUTION

Hello Vanderlei,
After some time, I found the solution to my problem. Apparently, to be able to replicate the multirow variables in the agent's view in the same structure as the form, we first need to insert a record in the sc_item_produced_record table, and only then insert into item_option_new or question_answer.
var gr = new GlideRecord('sc_item_produced_record');
gr.initialize();
gr.producer = 'sys_id_item_catalog';
gr.record_table = 'name_table';
gr.task = 'sys_id_requested';
gr.record_key = 'sys_id_requested';
gr.insert();

 The link that helped me understand was: https://www.servicenow.com/community/itsm-forum/copy-multi-row-variable-set-to-another-task/m-p/6479..., with the response from the user H_kon Sm_rvik.

Vanderlei, thank you for all your effort in trying to help me.

View solution in original post

4 REPLIES 4

Vanderlei
Mega Sage

Olá @Natan Felipe, tudo bem?
Vi que você é brasileiro então vou tomar a liberdade de escrever em português hahahaha

 

Variables sets do tipo multirow são arrays de objetos, segue um exemplo de código para adicionar uma nova linha em um variable set.

var current = new GlideRecord("table");
if (current.get("sys_id")){
    var mrv = current.variables.multi_row_name
    mrv.push({
        "mrv_field_1": value_1,
        "mrv_field_2": value_2
    })
    current.update()
}

 

Caso minha resposta tenha te ajudado, considere marcar como helpful, ou pode entrar em contato para que eu possa te ajudar

Eu vi sua resposta anterior, e desde já agradeço pela resposta. No entanto, o problema não é adicionar um valor em um campo, mas sim o próprio campo.

Atualmente, estou enfrentando a necessidade de adicionar campos no formulário, mas, no caso da MRV, é importante que eles sejam formatados de maneira a se assemelharem a uma tabela, como é exibido no portal. O problema é que, da forma como estou inserindo os campos, eles são adicionados um a um, o que faz com que o layout de tabela seja perdido, ao contrário do que é comum no portal.

Olá, tudo bem?

Dê uma olhada nessa API: 
suainstancia.service-now.com/$restapi.do?ns=877311&service=Item%20de%20Cat%C3%A1logo&version=&resource_id=952cf7ef937d3110694abc2efaba1034

Ela possibilita criar registros via integração usando record producer, assim seus registros nao terão o problema que foi mencionado anteriormente.


Hello Vanderlei,
After some time, I found the solution to my problem. Apparently, to be able to replicate the multirow variables in the agent's view in the same structure as the form, we first need to insert a record in the sc_item_produced_record table, and only then insert into item_option_new or question_answer.
var gr = new GlideRecord('sc_item_produced_record');
gr.initialize();
gr.producer = 'sys_id_item_catalog';
gr.record_table = 'name_table';
gr.task = 'sys_id_requested';
gr.record_key = 'sys_id_requested';
gr.insert();

 The link that helped me understand was: https://www.servicenow.com/community/itsm-forum/copy-multi-row-variable-set-to-another-task/m-p/6479..., with the response from the user H_kon Sm_rvik.

Vanderlei, thank you for all your effort in trying to help me.