Regaring client Script

AbhishaS
Tera Contributor

I am not able to run onChange and onSubmit client scripts in my PDI for both Zurich and Yokohama versions. Since the scripts are correct, please suggest an alternative option.

 

 

 1)  if (isLoading || newValue === '') {
        return;
    }
 
    //Type appropriate comment here, and begin script below
    if (newValue == "Software") {
        g_form.addInfoMessage('Testing Template');
        g_form.setValue('short_description', "Incident From client Script");
        g_form.disableAttachments();
 
    } else if (newValue == "Database") {
        g_form.addErrorMessage('Error fom an change client script');
        g_form.disableAttachments();
        g_form.setMandatory('assignment_group', true);
        g_form.setSectionDisplay('related_records', false);
 
    } else {
        g_form.clearMessages();
        g_form.enableAttachments();
        g_form.hideRelatedList('task_ci');
    }
}
=====================================================================================
 
AbhishaS_0-1770449777422.png

 

3 REPLIES 3

Craig Gruwell
Mega Sage

Hi @AbhishaS,

 

From the looks of your OnSubmit script, it appears you are requiring a value for assignment_group for submission, but the onChange script you provided makes the assignment_group mandatory only for "Database" option, which then questions why you need the OnSubmit script anyway, since if "Database" is selected and requires Assignment Group to be selected, the form will naturally not allow submission until it is completed.  If another option (other than "Database") is selected, then it should allow submission (assuming no other required fields are not yet completed on the form).

 

Sarthak Kashyap
Mega Sage

Hi @AbhishaS ,

 

I tried your client script in my PDI and it works for me please check below OnSubmit script 

function onSubmit() {
   //Type appropriate comment here, and begin script below
   var ag = g_form.getValue('assignment_group');

   if(!ag || ag == ""){
	alert("Please fill out manadatory field - Assignment Group");
	g_form.setMandatory("assignment_group", true);
	return false;
   }
   
}

SarthakKashyap_0-1770480606540.png

Result 

SarthakKashyap_1-1770480684205.png

Once I select ok it make assignment group as mandatory 

SarthakKashyap_2-1770480711119.png

 

 

Now Check correct OnChange Client script 

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

    //Type appropriate comment here, and begin script below
	alert("New Value = " + newValue);
    if (newValue == "software") {
        g_form.addInfoMessage('Testing Template');
        g_form.setValue('short_description', "Incident From client Script");
        g_form.disableAttachments();

    } else if (newValue == "database") {
        g_form.addErrorMessage('Error fom an change client script');
        g_form.disableAttachments();
        g_form.setMandatory('assignment_group', true);
        g_form.setSectionDisplay('related_records', false);

    } else {
        g_form.clearMessages();
        g_form.enableAttachments();
        g_form.hideRelatedList('task_ci');
    }

}

SarthakKashyap_3-1770480903764.png

 

Result 

SarthakKashyap_4-1770480923057.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

@AbhishaS ,

 

In OnChnage make newValue if condition with small case , database and software

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak