Update the Custom table when the MRV's records are modified, added or deleted in the service catalog form

Bhavana Reddy
Mega Guru

Hello Guys,

Can anyone please point me in the right direction

Note : We have a MRV- Equipments and the values are stored in Custom table

We have developed a functionality to resubmit the catalog item with additional data and we are loading the previous values submitted earlier by the user and also Auto populating the MRV's data from the Custom table when the user selects "Resubmit existing order"

Now the Client requirement is, when ever the data in the MRV"s is Updated, added or deleted  the corresponding record in the Custom table should be updated, added and deleted.

Can anyone please point me in the right direction to achieve this please?

 

Any suggestions will be highly appreciable!!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

once catalog item is submitted in workflow run script do this

1) get the MRVS json

2) iterate it for every row

3) query your custom table with correct fields

4) determine if the row is new or existing

5) if new then insert, if existing then update the fields

6) compare the recently submitted MRVS JSON with the earlier JSON and accordingly delete the record

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

13 REPLIES 13

@Bhavana Reddy 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

 

I am still working on it and i will update you once done 

 

Thank you!!

I was little bit confused to compare 2 JSON strings so what i did was, first i deleted the data from the custom table after every Update request was submitted and then added rows again to the custom table( In this way it doesnot require the need to compare whether data is deleted, added or updated on MRV's)

var orderLine = new GlideRecord('sn_ind_tmt_orm_order_line_item');
orderLine.addQuery('order', current.variables.customer_order_no);
orderLine.query();
if (orderLine.next()) {
var orderLineItemId = orderLine.sys_id;
var equipment = new GlideRecord('sn_ind_tmt_orm_equipments');
equipment.addQuery('u_customer_order_line_item1', orderLineItemId);
equipment.query();
while (equipment.next()) {
equipment.deleteRecord();
}
//To fill the values of the MultiRow variable set data in the custom table
var variableValue = current.variables.list_of_equipment;
var parser = JSON.parse(variableValue);
var gr = new GlideRecord('sn_ind_tmt_orm_equipments');
for (var i = 0; i < parser.length; i++) {
gr.initialize();
gr.u_vendor = parser[i].vendor;
gr.u_equipment_type_model_no = parser[i].equipment_type_model_no;
gr.u_quantity = parser[i].quantity;
gr.u_rack_units = parser[i].rack_units;
gr.u_customer_order_line_item1 = orderLineItemId;
gr.insert();
}

 

@Bhavana Reddy 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader