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

Mike Patel
Tera Sage

Instead of using || you need to use && 

OlaN
Giga Sage
Giga Sage

Hi,

The condition you are evaluating is a bit off.

The state field value will be "rejected" ("Rejected" is the display value).

Mike suggested to switch from OR statement ("||") into and AND statement ("&&") but that won't work either, as long as you compare with both, the statement will never be true.

 

So change your condition into only checking the value, not the display value.

if (g_form.getValue('state') == 'rejected') {
	// some code to run when state is rejected
}
else {
	// optional some code to run when state is NOT rejected
}

Rae Khan
Tera Contributor

Hi, for whatever reason Mike's solution works and the one suggested does not. I tried what you had suggested multiple times earlier with no luck. Thank you anyways!

Yes, Mikes suggestion works, in the manner that the alert will not trigger.

But like I said earlier, that code will NEVER trigger the alert, because it will never evaluate to true if comparing to both "Rejected" AND "rejected"
Because the value is "rejected" so part one is always false, and part two is always true.

I changed the condition from "!=" into "==" and put in an else statement to use when the state is not rejected.

Thought you should know, use the solution you feel works best for you.