MRVS on load Not fetching its own value from g_form

Aditya Kumar1
Tera Contributor

Hello Experts,

 

I'm stuck in a situation where i've a mrvs backend name "isp" i wrote a small on load catalog client script inside that mrvs that will fetch the value of its own at on load,

 

it has two record already but its not fetching those records i want that when i click to "add" button in mrvs 

then this on load should trigger and bring me that mrvs array 

 

 

 

 

'[{"id_isp":"ISP02139- 1","isp_component_type":"Primary"},{"id_isp":"ISP02139- 2","isp_component_type":"Secondary"}]'

 

 

 

this is the output of that mrvs i expect in alert where it has two records.
and this is the script i'm trying to fetch 

 

 

 

function onLoad() {
	
    alert('test');
    alert(g_form.getValue(JSON.parse(g_form.getValue('isp'))[0].isp_component_type));

}

 

 

AdityaKumar1_0-1699531418909.png

this is my catalog client script on mrvs 
please help me in this.

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

This is likely due to the fact that the MRVS is loaded after the form, so the script is running too soon.  Try adding a delay like this:

function onLoad() {
    //MRVS is loaded after the form is loaded. Hence setting a delay of 2 secs.
    setTimeout(function() {
        getMRVS();
	}, 2000);
}

function getMRVS() {
    alert('test');
    alert(g_form.getValue(JSON.parse(g_form.getValue('isp'))[0].isp_component_type));
}

 

AdityaKumar1_0-1699537149150.png

AdityaKumar1_1-1699537206590.png

 

// function onLoad() {
	
//     alert('test');
// 	alert(g_form.getValue('producer.isp'));
//     alert(g_form.getValue(JSON.parse(g_form.getValue('isp'))[0].isp_component_type));
	
// }

function onLoad() {
    //MRVS is loaded after the form is loaded. Hence setting a delay of 2 secs.
    setTimeout(function() {
        getMRVS();
	}, 2000);
}

function getMRVS() {
    alert('test');
    alert(g_form.getValue(JSON.parse(g_form.getValue('isp'))[0].isp_component_type));
}

 

no luck on this brad.

Sorry, I missed that you were running this script onLoad of the MRVS (when adding a row).  Keep this in your back pocket for when you want to retrieve/modify the MRVS contents when the RITM or Catalog Task form loads.  To get the MRVS contents onLoad of the add a row dialog, use g_service_catalog

https://docs.servicenow.com/bundle/tokyo-api-reference/page/app-store/dev_portal/API_reference/g_ser... 

function onLoad() {
    alert('test');
    alert(JSON.parse(g_service_catalog.parent.getValue('isp'))[0].isp_component_type);
}

 

Brad this works fine but now i'm unable to access main record producer

variables.

AdityaKumar1_0-1699954215885.png

just trying to access iata code from main record producer 

AdityaKumar1_1-1699954281686.png