ClientScript - onSubmit() - How to get value of a reference field by dot walking?

Halo10110
Giga Contributor

I am creating onSubmit client script and need to access of the reference field's table field value...I tried it by dotwalking but it didnt let me...I would liek to compare two values like this on my form (both reference fields)...anyone can help me?

I tried this:

function onSubmit() {
	if(g_form.getValue('u_business.u_active') == false){
		alert('Record submission aborted.');
		return false;
	}

with no luck...

 

7 REPLIES 7

That's right, my bad. You can edit and modify the rest of your code 🙂 I have seen Ankur has given good code for this.

Regards, Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

ServiceNow SA
Kilo Guru

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

You cannot dot walk in client script on reference field/variable

try to use getReference with callback

function onSubmit(){

var business = g_form.getReference('u_business', getValue);

}

function getValue(business){

if(business.u_active.toString() == 'false')

return false;

else

return true;

}

 

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader