Retrieve Values from a MRVS

Jose Agudelo
Tera Contributor

I'm trying to collect field value from a MRVS, if there is a row with a Public Domain Value it will show an attachment variable in the same catalog Item (Like a UI Policy).

Is there a way to accomplish this requirement?

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }


    var multiRowVariableSet = JSON.parse(g_form.getValue('dominio_remitente_de_confianza'));
    var hasPublicDomain = false;

    // Recorre cada fila del MRVS para verificar si hay un dominio público
    for (var i = 0; i < multiRowVariableSet.length; i++) {
        if (multiRowVariableSet[i].dominio_publico_privado == 'público') { 
            hasPublicDomain = true;
            break;
        }
    }
}

 

 

I was using this previous version of the script that was working but only with the last row inserted:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var domain = g_form.getValue('dominio_publico_privado');

    if (domain !== 'público') {
        if (this) { // Service Portal method
            this.cat_g_form.setMandatory('adjuntar_carta_de_aceptaci_n_de_riesgos', false);
        } else { // native UI method
            parent.g_form.setMandatory('adjuntar_carta_de_aceptaci_n_de_riesgos', false);
        }
    } else {
        if (this) { // Service Portal method
            this.cat_g_form.setMandatory('adjuntar_carta_de_aceptaci_n_de_riesgos', true);
            this.cat_g_form.setVisible('adjuntar_carta_de_aceptaci_n_de_riesgos', true);
        } else { // native UI method
            parent.g_form.setMandatory('adjuntar_carta_de_aceptaci_n_de_riesgos', true);
            parent.g_form.setVisible('adjuntar_carta_de_aceptaci_n_ocultaci_n_de_riesgos', true);
        }
    }
}

 

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

The new script looks good, just add the g_form.setVisible and g_form.setMandatory lines (without the stuff preceding g_form in this case) after the for loop, and make sure the script Applies to A Catalog Item instead of A Variable Set.

I'm getting an error console when using the new one

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }


    var multiRowVariableSet = JSON.parse(g_form.getValue('dominio_remitente_de_confianza'));
    var hasPublicDomain = false;

    // Recorre cada fila del MRVS para verificar si hay un dominio público
    for (var i = 0; i < multiRowVariableSet.length; i++) {
        if (multiRowVariableSet[i].dominio_publico_privado == 'público') { 
            hasPublicDomain = true;
            break;
        }
    }
}

 

JoseAgudelo_0-1733865172181.png

 

I'm applying the Catalog Client Script to the Variable Set

This syntax will work applied to the Catalog Item, not the Variable Set, but the tricky part is triggering it when a row is added or edited.  A workaround is to trigger it onChange of a mandatory variable that would only be populated after the MRVS.  Not a great user experience, but you could also make the variable always visible to give them the chance to supply the attachment, then onSubmit of the Catalog Item, use a script like this to check the MRVS contents to determine if the attachment variable should be mandatory, then make is so and prevent submit if it is empty.  You could also go with the original script either onChange of a MRVS variable or onSubmit, but only set the variable mandatory and visible true if the condition is met, not the reverse if the condition is not met for this one row.  To further confuse the issue, you can get the rest of the MRVS contents onSubmit of the Variable Set (not the new row) using the same parent.g_form / this_cat_g_form with getValue and the MRVS internal name like you are in the new script, so you can determine if the new row

g_form.getValue('dominio_publico_privado')

or the rest of the MRVS

parent.g_form.getValue('dominio_remitente_de_confianza')

(then parse it and use your for loop) meets the condition for the required attachment.