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

Akash4
Kilo Sage
Kilo Sage

Hello,

You cannot directly use a dot walking in Client Script, instead do a callback function using the API - getReference. I will try giving you the code in a while.

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.

Halo10110
Giga Contributor

Thanks, I am getting so stuck because I need to compare two reference field values...and if they are on form equal then I need to abort submition.

If I consider the above script, this will work. I used company field as reference field here.

function onSubmit(){
	var companyValue = g_form.getReference('company', callbackfn);
	function callbackfn(companyValue) { 
		if (companyValue.active == 'false') {
			alert('Record submission aborted.');
			
		}}
	return false;
	}

If your case is to validate two reference fields and if the the reference field table's list of records are very big in count, I suggest you go for Script Include and GlideAjax functionality.

If you think the load to the system is minimal then use the same lines of code for the second call back function.

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.

Halo10110
Giga Contributor

Thanks, however this wont update the form at all, meaning even if the value is "true"

companyValue.active == 'false'