How to create records in a table from MRVS?

Apurv Kumar
Tera Expert

I Want to populate my mrvs data from record producer to a table under a related list of a record form.

I have created a custom table in which similar fields are created as i have in the mrvs + record reference field + mrvs name reference field

In the producer side i have used this code to initialize the record on the table mentioned:

 

(function() {

var mrvs = producer.business_function;

var length = mrvs.getRowCount();
for(var i = 0; i < length; i++) {
var row = mrvs.getRow(i);
var cells = row.getCells();

var businessFunction = new GlideRecord('incident_task');
businessFunction.initialize();
businessFunction.setValue('af_opportunity', current.getUniqueValue());
businessFunction.setValue('business_function', cells[0].getDisplayValue());   //field type select box
businessFunction.setValue('add_info', cells[1]);

businessFunction.setValue('product_services', cells[1].getDisplayValue());  //field type select box
businessFunction.insert();
}

})();

 

Kindly help me to achieve this..

Thank You

1 ACCEPTED SOLUTION

Hello,

 

Thanks for your help...This code worked well when i parsed the MRVS rows into JSON and then after initializing the record, removed the setValue and replaced with:

businessFunction.business_function = mrvs[i].business_function;

businessFunction.add_info = mrvs[i].add_info;..............and so on

 

View solution in original post

6 REPLIES 6

Apurv Kumar
Tera Expert

in place of incident task table i have used another custom table

Amelia5634
Tera Contributor

Creating records in a table from MRVS requires first creating a table. This can be done by using a Structured Query Language (SQL) command such as CREATE TABLE. The table should include the attributes that need to be entered for each record. Once the table is created, the INSERT command can be used to add individual records to the table. For example, INSERT INTO table_name (field1, field2, field3...) VALUES (value1, value2, value3...). This command will insert a new record into the test table, with the specified values for each field. Additionally, if the table has been created with constraints, any attempts to add records that violate the constraints will be blocked.

I have already created a table and tried creating records with the script mentioned above.

 

Thank you

Teja11
Giga Guru

Hi @Apurv Kumar ,

 

use the below code, it works

 

var mrvs = producer.business_function;

var length = mrvs.getRowCount();
for(var i = 0; i < length; i++) {

var businessFunction = new GlideRecord('incident_task');
businessFunction.initialize();
businessFunction.setValue('af_opportunity', current.getUniqueValue());
businessFunction.setValue('business_function', mrvs[i].business_function);   //business_function - variable backend name
businessFunction.setValue('add_info', mrvs[i].add_info);
businessFunction.setValue('product_services', mrvs[i].product_services);  
businessFunction.insert();
}

 

Regards,

Teja

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.