Client Script for Error Message

aubreysallee
Kilo Contributor

Hi I'm trying to write a client script to make an error message when the "Portfolio" field is changed to "AIT" and the choice field below it (A question about   being submitted on behalf of a Business Partner) has not be answered already. This is the script I have so far, but it is not working. The commented out part I'm not sure if I need or not, I had it originally but was trying to see if it would work without it. Any ideas would be very appreciated!

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

if(g_form.getValue('portfolio')=='AIT'
  && g_form.getValue('u_choice_1')==''){

  g_form.addErrorMessage('Please answer "Business Partner" Question');

  }

}

11 REPLIES 11

Anurag Tripathi
Mega Patron
Mega Patron

Hi Aubrey,



First thing: since you have the condition based on portfolio and u_choice_1 both, id say you need to write 2 onchange scripts(one for each field) and write the same script again. This way iot wont matter which order these fields are populated in.



Secondly, make sure that the actual values of these fields are same as you are expecting, the actual value and display values might be different. You can check these by opening the frol, adding these values on the form...then hit control+alt+shift+j on the keyboard that will open up client side java script executor and inside that paste these these lines and run



alert('portfolio='+(g_form.getValue('portfolio'));


alert('u_choice_1='+(g_form.getValue('u_choice_1'));


-Anurag

Thanks Anurag,



The second field is actually hidden unless the first field's value is 'AIT' so I don't think that will be an issue.



I followed your steps with the java script editor but it did not do anything when I clicked "Run my code".


Sorry...typos


run this


alert('portfolio='+g_form.getValue('portfolio'));


alert('u_choice_1='+g_form.getValue('u_choice_1'));


-Anurag

Ok it worked this time, and for portfolio it said =9d2af2ef4f0d5200a7cc0ea28110c76e. I changed the value in the script from portfolio to the sys id, but it is still not showing an alert when the portfolio field changes to AIT.



I have the "Field name" field filled in as "Portfolio", is this correct?