Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get the MVRS details from sc_req_item using script ?

String
Kilo Sage

Hi Team ,

Am trying to get the catalog item details from the  sc_req_item and am able to get the variables but unable to get the MVRS details ,Please guide me 

am using the below code 

 

 

var pageRecords = [];

 var grRequestedItem = new GlideRecord('sc_req_item');

    grRequestedItem.orderByDesc('sys_created_on');

grRequestedItem.query();

while (grRequestedItem.next()) {

var resJSON = {

            case: grRequestedItem.request.parent.getDisplayValue(),

            number: grRequestedItem.getValue('number'),

};

if(grRequestedItem.getDisplayValue(‘MVRS')){

gs.info(grRequestedItem.getDisplayValue(‘MVRS));//am not getting the MVRS details 

}

for (var prop in grRequestedItem.variables) {

  if (grRequestedItem.variables[prop] != '') {

var variable = grRequestedItem.variables[prop].getDisplayValue();

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

                    delete resJSON[toDelete[i]];

                    resJSON[prop] = variable;

                }}}

pageRecords.push(resJSON);
}

response.setBody(pageRecords);

   

String_0-1693479501066.png

 

 

please guide me

1 ACCEPTED SOLUTION

@String 

syntax to get MRVS json is this

grRequestedItem.variables.MVRSVariableSetName

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@String 

data for MRVS is in json format

what's your requirement here?

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

Hi @Ankur Bawiskar  ,

thanks for your quick response 

 

Requirement :

Get the serial number  from the MVRS and append to resJSON in array format 

 

=============Expected json :========

{
"result": [
{
"case": "CS9207",
"number": "RITM045",
"please_provide_the_invoice_number": "dwdw",
"please_enter_a_short_description_of_your_query": "fwqf",
"please_provide_the_case_number_if_known": "CS9206",
"serialNumbers": [123,345]
},
{
"case": "CS06",
"number": "RI1944",
"please_provide_the_invoice_number": "fwqf",
"please_enter_a_short_description_of_your_query": "fqwfqf",
"please_provide_the_case_number_if_known": "CS558",
"serialNumbers": [123,345]
}
]
}

 

 

========am getting the below json =========

{
"result": [
{
"case": "CS9207",
"number": "RITM045",
"please_provide_the_invoice_number": "dwdw",
"please_enter_a_short_description_of_your_query": "fwqf",
"please_provide_the_case_number_if_known": "CS9206"
},
{
"case": "CS06",
"number": "RI1944",
"please_provide_the_invoice_number": "fwqf",
"please_enter_a_short_description_of_your_query": "fqwfqf",
"please_provide_the_case_number_if_known": "CS558"
}
]
}

@String 

did you try parsing the json?

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

@Ankur Bawiskar  not getting the MVRS/JSON details