The CreatorCon Call for Content is officially open! Get started here.

Client script help

Gemma4
Mega Sage

Hi Everyone,

 

Hi everyone,

I am trying to make variables mandatory after the request has been submitted, if the user has the pmsubmitter rule and if a custom field additional information is set to yes. I'm attempting to do this with a onchange client script using the field additional information. Below are the 2 scripts I have tried that have gotten the closest results (tired several others with not luck)  The first script results: when I impersonate a user after the request has been submitted, with the pmsubmitter role the platform is showing a black * instead of red indicating the field is required. In addition, the user that submits the request needs to be able to show these variables as required on the portal after summitted and their manager selects Yes at additional information. Unfortunately the variables are not getting set as required on the portal. Is this possible? In the past I've utilized sctasks and a flow to achieve.

 

first script- will only set test4 required if user with pmsubmitter selects yes at additonal informaiton. However, a user with PM role (manager) will be the one selecting yes at additional information 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (g_user.hasRoleExactly("pmsubmitter"))

if (newValue === 'Yes') //yes
g_form.setMandatory('test4', true);
else
g_form.setMandatory('test4', false);
}

 

 

 

second script- not making anything required

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
 
//Type appropriate comment here, and begin script below
 
}
 
//If additional informatio is true, and role is pmsubmitter then variable is mandatory
 
//if(newValue == 'true' && g_user.hasRoleExactly("pmsubmitter")) {
//if(newValue == 'yes' && g_user.hasRoleExactly("pmsubmitter")) {
if(newValue == 'Yes' && g_user.hasRoleExactly("pmsubmitter")) {
// g_form.setMandatory('test4', true); 
// g_form.setMandatory('variables.test4', true);   
//
// g_form.setMandatory('description', true); 
g_form.setMandatory('variables.test4', true);
}
else {
//g_form.setMandatory('description', false); 
//g_form.setMandatory('test4', false); 
g_form.setMandatory('variables.test4', true);
}

 

 

 

Thank you in advance for any guidance you can provide!

6 REPLIES 6

Tushar
Kilo Sage
Kilo Sage

Hi @Gemma4 

 

The second script you provided is not making anything mandatory because the newValue variable is always empty. This is because the onChange script is only triggered when the value of the control changes.

In this case, the value of the additional information field is never changed, so the newValue variable is always empty.

Try to use the following script:

 

 

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

// If the user has the pmsubmitter role and the additional information field is set to yes, then make the variable mandatory
if (g_user.hasRoleExactly("pmsubmitter") && newValue === "Yes") {
g_form.setMandatory('variables.test4', true);
} else {
g_form.setMandatory('variables.test4', false);
}
}

 

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

 

Thank you for the feedback. Unfortunately the variable test4 is still not required after the request is submitted.  

I tested further and the odd thing is the variable will become required only if the user with pmsubmitter selects additional information = yes.  However the manager will determine that and the manager has the role pm. I'm trying to make the variable required AFTER the manager selects additional information = yes.

Is this possible?

I checked this further and it looks like the issue is the role defined in the beginning is what is setting additional information =yes and then the variables are required for that user. However, I need to add 2 roles to the script. PM user should set the variable additional information to yes. The variable should only then be required for the user with pmsubmitter role. Is there a better way to do this or can I get help with the script?