onLoad Get Value Client Script Not Working

Rae Khan
Tera Contributor

Hi all, 

 

Despite my best efforts using the getValue in a Client Script for onLoad, it does not seem to work

If the state is rejected, the alert should not trigger, yet it does. 

 

I have tried several times, with different variations but no luck. Does anyone have a workaround on this?

Would be much appreciated. 

 

RaeKhan_0-1691160304276.pngRaeKhan_1-1691160355941.png

 

 

Thank you

8 REPLIES 8

Rahul Talreja
Mega Sage
Mega Sage

Hi @Rae Khan ,
g_form.getValue('state') !='Rejected' -> This statement will always be True (As it is a Display Value NOT the Value)
g_form.getValue('state') !='rejected' -> This statement will determine based on your value of state.

 If you are using || which means OR, and one of the conditions is always true so ultimately it will result into TRUE, and the code will work always.

If you are using && this will always check for both the condition to be TRUE and, in this case, when you will actually have the state not as "rejected" it will work, and Code will work.

So, in either of the case "g_form.getValue('state')!='Rejected'" is of no use.


You can try using:

 

 

 

if (g_form.getValue('state') != 'rejected') {
	alert("Hello");
}

 

 

Hope this will work for you!!
Its Working for me!

 

 

 

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Abhijit
Tera Expert

do not use below , it is not working i think it is bug

if (g_form.getValue('state') != 'rejected')

I modified to work it , it worked in below PDI

 

if (g_form.getValue('state') == "requested" || g_form.getValue('state') == "not requested" || g_form.getValue('state') == "approved" || g_form.getValue('state') == "cancelled" || g_form.getValue('state') == "not_required" )
alert('hello' + g_form.getValue('state') );

Christopher096
Tera Guru
Tera Guru

Like @Mike Patel  mentioned, you can use the and operator “&&” in the IF condition instead of the “||” OR operator

Sandeep Rajput
Tera Patron
Tera Patron

@Rae Khan You are seeing the alert because your first condition in if statement is evaluating to true.  Update your code as follows.

function onLoad(){
//Type appropriate comment here,
if(g_form.getValue('state')!='rejected'){
    alert('HELLO');
   }
}

Hope this helps.