How to show Annotation section , based on 3 conditions using onChange Client script.

Neelavathi M
Tera Contributor

Hi All,

I have a requirement to show Annotation section, if 3 conditions are satisfied and  these 3 condtions are from 3 individual fields which are choice type.

 

NeelavathiM_0-1738949489306.png

and I have written a onChange client script for achieving this , but i am able get only 1st field value , others are coming as empty , so condition is not satisfying to show Annotaion section.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var a1= g_form.getValue('compliance_risk');
    var a2= g_form.getValue('complexity_risk_global_and_functional');
    var a2= g_form.getValue('operational_risk');
	alert('1st--'+ a1);
	alert('2nd--'+a2);
	alert('3rd--'+a3);
    if (a1== 'yes, direct impact' && a2== 'global department' && operationalrisk == 'Yes, Quality Agreement '){
        $('primPurpose').up().show();
        g_form.setDisplay('primary_purpose_of_document', true);
        //Type appropriate comment here, and begin script below

    }
}

 

 

 

So please suggest me how to achieve this requirement.
Appreciate your support.

 

Thanks.

 

10 REPLIES 10

Jon Hogland
Tera Guru

Hi, Neelavathi. It looks like your code defines the value 'a2' twice. Fixing that issue might allow you to get the values you need for your script.

 var a1= g_form.getValue('compliance_risk');
var a2= g_form.getValue('complexity_risk_global_and_functional');
 var a2= g_form.getValue('operational_risk'); // 'a2' duplicated here. Fix as 'a3'. 

That being said, have you considered utilizing a UI Policy to fulfill your requirement? It would save you the trouble of scripting and prevent easy to miss errors that might occur during scripting. Please let me know if you'd like further assistance, and I can either work with you to build your script differently (if it still doesn't work), or to create a UI Policy that fits your need.

 



If I've at all helped, please return the favor by clicking the thumb next to my post. Thanks!

hi @Jon Hogland ,

Thanks for reply, I have fixed it , by creating Onchange script on 3rd field, by the selection of 3rd field on the form, 1st and 2nd values would be entered by the user, so fetching those values and comparing those , and then populating the Annotation Section.

Viraj Hudlikar
Giga Sage

@Neelavathi M 
Below are some correction to your code. Also, while doing comparison with incoming value I believe you are doing with value not label.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var a1= g_form.getValue('compliance_risk');
    var a2= g_form.getValue('complexity_risk_global_and_functional');
    var a3= g_form.getValue('operational_risk'); // Here you had variable as a2
	alert('1st--'+ a1);
	alert('2nd--'+a2);
	alert('3rd--'+a3);
    if (a1== 'yes, direct impact' && a2== 'global department' && a3 == 'Yes, Quality Agreement ') //in this you were checking operationalrisk where such variable is not defined changed to a3
{
        $('primPurpose').up().show();
        g_form.setDisplay('primary_purpose_of_document', true);
        //Type appropriate comment here, and begin script below

    }

//In case you want to hide your annotation you can use below syntax.
//     $('primPurpose').up().hide();    
   
}

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

Thanks & Regards
Viraj Hudlikar.

hi @Viraj Hudlikar , thanks for response.

 I have fixed it , by creating Onchange script on 3rd field, by the selection of 3rd field on the form, 1st and 2nd values would be entered by the user, so fetching those values and comparing those , and then populating the Annotation Section.