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

I also tried the following onchange scirpt with no luck

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

@Gemma4  When you are writing onchange script please write on load for the script also as below.

 

onChange of Additionion informtion

  • function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
 
 
 
if(g_user.hasRoleExactly('on’)&& newValue == "Yes")){
 
    if (g_user.hasRoleExactly("pmsubmitter"))
 
g_form.setMandatory('variables.test4', true);
 
}
}

 
onload script 
function onload{
var Addinfo =g_form.getValue(‘additional_information’);
if(g_user.hasRoleExactly("pm") && Addinfo == "Yes")){
 
    if (g_user.hasRoleExactly("pmsubmitter")){
 
g_form.setMandatory('variables.test4', true);
}
}
}