Set variable ReadOnly when Multi Row Variable Set not empty

SamuelChang
Tera Contributor

Hi all,

 

I need some help or guidance on how to set a variable Read-Only when the Multi Row Variable Sets (MRVS) not empty i.e. once it populated at least one item.


Basically, once I added Report Name & Email the field outside of MRVS should be set to Read-Only

SamuelChang_0-1722362720233.png

 

I've tried onLoad client script but it doesn't work quite right

function onLoad() {
	var mrvs = JSON.parse(g_form.getValue('report_name_and_email'));
	if(mrvs.length > 0) {
		g_form.setReadOnly('add_or_remove', true);
	}
}

Is there something else that I missed?

 

Thank you in advance!

17 REPLIES 17

@Saloni Suthar 

 

Thank you for your help but it doesn't seem to work on my my PDI is there something I missed?

 

1. Multiline text

SamuelChang_0-1722436003692.png

 

2. Custom variable

SamuelChang_1-1722436047127.png

 

3. Widget

SamuelChang_2-1722436110086.png

 

4. Client script

SamuelChang_3-1722436158067.png

 

I'm pretty sure I did everything

First of all, are you getting mrvs value in your hidden variable?

 

Try below in client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        // Do nothing if the form is loading
        return;
    }

    if (newValue === ' ' ) {
        g_form.setReadOnly('report_email', false);
    } else {
        g_form.setReadOnly('report_email', true);
    }
}

How can I check if I'm getting mrvs value? Like a log somewhere?

 

Here is the updated client script per your suggestion

SamuelChang_0-1722437680045.png

 

Before adding anything

SamuelChang_1-1722437709259.png


After select Add selection then add item into mrvs

SamuelChang_2-1722437758394.png

The "Report and email" still not set to Read Only

 

Same thing on Service Portal

SamuelChang_3-1722437855117.png

 

MRVS value should be populated in your hidden variable. For testing, make sure hidden variable is visible on the form

It does not populate in my hidden variables

SamuelChang_0-1722438544471.png