Getting Error - MRVS Data fetch RITM to catalog item

Amit Naik1
Tera Contributor

 

I am trying to copy the MRVS data from an existing RITM and put it in a new catalog item by using GlideAjax, and when I am trying to put the request in the cart or submit, it gives me an error: "Something went wrong on your request; it could not be submitted. Please contact your system administration."

I used the following method, but it didn't work. Does anyone have a solution for this or have come across this issue before? 

Server side - 

getMRVS:function(){
	//var aa={};
	var gr=new GlideRecord('sc_req_item');
	gr.get('444db8712f96b01042162b5df699b654');
	var mrv=gr.variables.my_values.toString();
	return  JSON.stringify(mrv);
}

Client side -

var gr=new GlideAjax('AjaxUtil');
gr.addParam('sysparm_name','getMRVS');
gr.getXML(GetMRVS);
function GetMRVS(response){
	var answer = response.responseXML.documentElement.getAttribute("answer"); 
	var mrv=JSON.parse(answer);
	console.log(mrv);
	g_form.setValue('my_values',mrv);
}

 

AmitNaik1_0-1711465057127.png

 

 

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

Setting the value of the MRVS on the current form is going to be looking for a string, so try it without the JSON.parse line.

@Brad Bowman  Still getting the same error.

Similarly, you don't need to JSON.stringify the existing JSON-formatted string value in the Script Include.  To follow clean coding standards to reduce errors or unexpected results, you should always put a GlideRecord get or next() inside of an if or while condition so that the following code is only executed if the record is found.  You should also always return something from a Script Include, so declare the return variable at the beginning, outside of any if conditions, and make sure the return is also outside of any condition blocks.  I got this scenario to work without error with these scripts.  I'm using the native UI by the way - it may work differently in Service Portal / Employee Service Center / ...

var gr=new GlideAjax('AjaxUtil');
gr.addParam('sysparm_name','getMRVS');
gr.getXML(GetMRVS);

function GetMRVS(response){
    var answer = response.responseXML.documentElement.getAttribute("answer"); 
    g_form.setValue('my_values', answer);
}
getMRVS: function() {
		var mrv = '';
        var gr = new GlideRecord('sc_req_item');
        if (gr.get('444db8712f96b01042162b5df699b654')) {
            mrv = gr.variables.my_values.toString();
		}
		return mrv;
    },

 

@Brad Bowman  Unfortunately I am still getting same error.