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

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

How to uniquely identify the indivisual rows in the MRV's?

Suppose say 1st row is not updated and the 2nd row is Updated or deleted in the MRV's and 3rd row is added to MRV's , basically how to track the indivisual rows whether its updated , deleted or not

 

So far i was thinking to create a hidden variable inside the Mrv's and auto increment that variable for each row addition and use that unique value as a reference to Modify the corresponding Custom table records

 

Can you please suggest me !!

Hi,

you need to compare both the JSON strings

Regards
Ankur

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

Hello Ankur,

 

The values which was entered in the MRV's first time was below

variableSetValue::[ {
"vendor" : "Microsoft",
"model" : "v1",
"rack_unit" : "metre",
"equipment_type" : "Colo"
}, {
"vendor" : "Dell",
"model" : "ACer",
"rack_unit" : "kilo",
"equipment_type" : "Flex"
} ]

 

Next time when the MRV data is Updated we get the below JSON string

variableSetValue::[ {
"vendor" : "Microsoft",
"model" : "v1",
"rack_unit" : "metre",
"equipment_type" : "Colo1" // Update the custom table record
}, {
"vendor" : "Dell",
"model" : "ACer",
"rack_unit" : "kilo",
"equipment_type" : "Flex"
}, {
"vendor" : "1",
"model" : "1",
"rack_unit" : "1",
"equipment_type" : "1"  // Insert new Row in the Custom table
} ]

 

Can you please suggest me how to just compare 2 JSON strings and update/add/ delete the corresponding record in custom table 

Hi,

Steps

1) get the 2nd MRVS and iterate row by row

2) for each row of 2nd MRVS search in 1st MRVS and compare the values

3) if different then update

Regards
Ankur

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