Set Value on MVRS from the catalog form variable

Kaustubh k
Tera Contributor

Hello All,

 

Thanks for looking into the ask,

 

We have a catalog variable : Applications(list collector)

 

We have a mvrs: which has Applications(reference) field.

 

We need to create and set, each row for the applications selected on the Catalog form variable Application(list collector) on to the MVRS.

 

 

Any feedback on the same will be highly appreciable.

Thanks

 

12 REPLIES 12

Hello @Community Alums , thanks for the reply, we are able to map the list collector single value to one row, but multiple applications selected on MVRS is not adding extra row in MVRS.

 

The first row is only getting overridden.

 

if you could please check and help on the same.

 

Thanks

Community Alums
Not applicable

Hi @Kaustubh k ,

The issue was with the array that was not storing the values properly.
Please find the below client script that will solve your issue.

function onLoad() {
    var mrvsFieldName = 'mrvs';  // Name of your MRVS field
    var listCollectorFieldName = 'applications';  // Name of your list collector field

    var listCollectorValues = g_service_catalog.parent.getValue(listCollectorFieldName);
    if (!listCollectorValues) return;

    var selectedSysIds = listCollectorValues.split(',');

    var mrvs = g_form.getValue(mrvsFieldName);
    var mrvsData = mrvs ? JSON.parse(mrvs) : [];

    selectedSysIds.forEach(function(sys_id) {
        var ga = new GlideAjax('MRVSUtils');
        ga.addParam('sysparm_name', 'getUserInfo');
        ga.addParam('sysparm_id', sys_id);
        ga.getXMLAnswer(function(response) {
            var res = JSON.parse(response);
            if (res.length > 0) {
                var userInfo = res[0];
                mrvsData.push({
                    'selected_friends': sys_id,
                    'user_name': userInfo.user_name,
                    'email': userInfo.email
                });
                g_form.setValue(mrvsFieldName, JSON.stringify(mrvsData));
            }
        });
    });
}

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar