How do I compare 2 reference values in Client Script?

JD31
Kilo Expert

Hello guys,

I am trying to compare the values "Opened By" and "Resolved By" via a Client Script. I've tried both of the below code snippets, however they don't seem to work as expected. 

var openby = g_form.getReference('opened_by');
var resolveby = g_form.getReference('resolved_by');

if(resolveby == openby)
{
        g_form.setReadonly('u_firstcallresolution',true);
	g_form.setValue('u_firstcallresolution',true);
}
var openby = g_form.getValue('opened_by');
var resolveby = g_form.getValue('resolved_by');

if(resolveby == openby)
{
        g_form.setReadonly('u_firstcallresolution',true);
	g_form.setValue('u_firstcallresolution',true);
}

 

Please help!!

1 ACCEPTED SOLUTION

Could you please try giving an alert before the if condition and check what's the value in both the fields?

below is the script with the alert:

var openby = g_form.getValue('opened_by');
	var resolveby = g_form.getValue('resolved_by');
	alert("Opened By :"+openby+" Resolved By :"resolveby);
	if(resolveby == openby)
		{
alert("If Condition Satified");
		g_form.setValue('u_firstcallresolution',true);
		g_form.setReadOnly('u_firstcallresolution',true);
		
	}

With the above script you will get 2 alert with the first alert you will get to know the value coming up in both the field and with the second you will get to know that the if loop is been executed.

Please give a try and give an update so it will be easy to debug the issue.

View solution in original post

14 REPLIES 14

Hello Utpal, 

That doesn't seem to work! Any other way to do it?

Try:

g_form.getDisplayValue('ref_field');

Chaitanya Redd5
Tera Guru

Hi JD,

Please try the below updated code, It should work now.

var openby = g_form.getValue('opened_by');
	var resolveby = g_form.getValue('resolved_by');
	
	if(resolveby == openby)
		{
		g_form.setValue('u_firstcallresolution',true);
		g_form.setReadOnly('u_firstcallresolution',true);
		
	}

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Chaitanya

That is a no too.

Could you please try giving an alert before the if condition and check what's the value in both the fields?

below is the script with the alert:

var openby = g_form.getValue('opened_by');
	var resolveby = g_form.getValue('resolved_by');
	alert("Opened By :"+openby+" Resolved By :"resolveby);
	if(resolveby == openby)
		{
alert("If Condition Satified");
		g_form.setValue('u_firstcallresolution',true);
		g_form.setReadOnly('u_firstcallresolution',true);
		
	}

With the above script you will get 2 alert with the first alert you will get to know the value coming up in both the field and with the second you will get to know that the if loop is been executed.

Please give a try and give an update so it will be easy to debug the issue.