Unexpected value in g_form.getDisplayValue client script onLoad

jamess_
Tera Contributor

onLoad client script on Incident table. Functionality was intended to be: Check status and display message accordingly. Was not working as expected, so I added messages 1 and 2.

function onLoad() {
   //Type appropriate comment here, and begin script below
if (g_form.getDisplayValue('u_contractor_incident_no') > 0) {

	if (g_form.getDisplayValue('u_contractor_status') == '2') {
	g_form.addErrorMessage('Contractor Incident Complete. No further updates will be received.');
	}
	else if (g_form.getDisplayValue('u_contractor_status') == '3') {
		g_form.addErrorMessage('Contractor Incident Closed. No further updates will be received.');
	}
	else if (g_form.getDisplayValue('u_contractor_status') == '4') {
		g_form.addErrorMessage('Contractor Incident Cancelled. No further updates will be received.');
	}
	else if (g_form.getDisplayValue('u_contractor_status') == '10') {
		g_form.addErrorMessage('Contractor Incident Returned. No further updates will be received.');
	}
	else{}
	g_form.addErrorMessage('1. Contractor Status is ' + g_form.getDisplayValue('u_contractor_status'));
}
else {
	g_form.addErrorMessage('2. Contractor Incident number is ' + g_form.getDisplayValue('u_contractor_incident_no'));
}
}

 

Message #2 is now displaying, but the message reads "2. Contractor Incident number is INC000999999", and is the currently displayed Incident number, rather than the field specified. Am I somehow making a reference to the 'number' field, and not realizing it? I verified that the 'u_contractor_incident_no' is not the same value as the local Incident number.

Any assistance greatly appreciated.

1 ACCEPTED SOLUTION

This is strange. I'm out of ideas, but maybe try simply using g_form.getValue('u_contractor_incident_no');

View solution in original post

19 REPLIES 19

Hi,

Convert to int then apply condition

 

 

Thanks

Hi,

Use

var no = g_form.getDisplayValue('u_contractor_incident_no').toString();

if(no.lenght>0){

 

}

 

Thanks

Hi,

Sorry there is typo error

 

Form else condition it seams that u_contractor_incident_no is string type. All the field values are returned as string. So for u_contractor_incident_no either you can check with regx that it is a INC number or can check with length.

var no = g_form.getDisplayValue('u_contractor_incident_no').toString();

if(no.length>0){

 

}

 

 

// var regW = new SNC.Regex(/INC[0-9]{9}/);

 

Thanks

Is u_contractor_incident_no an integer field type? If no, you need to check the length like I provided in my example.

Also, you might want to fix your else:

	else{}

Global checked means it's running on all Views.

jamess_
Tera Contributor

I feel like we're drifting...My primary concern is that I have variables returning (what would be) current.number when I never referred to that field at all in the script. And yet, every variable is returning that value. I was troubleshooting the logic when I discovered the issue with the set value of the variable I'm working with. It SHOULD NOT be the current Incident number, or at least it was not intended to be, nor do I understand why it is so.

find_real_file.png