Getting error Cannot read property 'apply' of undefined

I have a several dropdown fields and I am using the change event to set a score field. The on change event seems to work fine while the form is loading but then throws an error when the dropdown is changed.

fd.spRendered(function() {

function setScore(rating, score, total) {
	console.log(rating);
	console.log(score);
	console.log(total);
	
	let r = fd.field(rating).value;
	let s = 0;
	
	
	console.log(r);
	
	if (r == 'Unsuccessful') 
		s = 1
	else if (r == 'Emerging') 
		s = 2
	else if (r == 'Successful')
		s = 3
	else if (r == 'Exceeds')
		s = 4
	else if (r == 'Exemplary')
		s = 5;
	
	fd.field(score).value = s;
}

fd.field('Communication').$on('change', setScore('Communication', 
'Communication_x0020_Score', 'Personal_x0020_Score'));
//	fd.field('Receptive').$on('change', setScore('Receptive', 'Receptive_x0020_Score', 'Personal_x0020_Score'));
//	fd.field('Flexibility').$on('change', setScore('Flexibility', 'Flexibility_x0020_Score', 'Personal_x0020_Score'));
//	fd.field('Relationships').$on('change', setScore('Relationships', 'Relationships_x0020_Score', 'Personal_x0020_Score'));
//	fd.field('Empathy').$on('change', setScore('Empathy', 'Empathy_x0020_Score', 'Personal_x0020_Score'));
//	fd.field('Balance').$on('change', setScore('Balance', 'Balance_x0020_Score', 'Personal_x0020_Score'));

fd.field('Employee').$on('change', function(value) {
fd.field('Title').value = value.DisplayText;
});
});

cityofnampaid.sharepoint.com-1578606045278.log (257.1 KB) performance_eval_Item_Edit.xfds (15.8 KB)

I started commenting out my code to see if I could find the offending code but that isn't working.

Hello @smithme,

Please use the following code to call a function with parameters under on change event.


fd.spRendered(function() {

	function setScore(rating, score, total) {
		console.log(rating);
		console.log(score);
		console.log(total);
		
		let r = fd.field(rating).value;
		let s = 0;
		
		
		console.log(r);
		
		if (r == 'Unsuccessful') 
			s = 1
		else if (r == 'Emerging') 
			s = 2
		else if (r == 'Successful')
			s = 3
		else if (r == 'Exceeds')
			s = 4
		else if (r == 'Exemplary')
			s = 5;
		
		fd.field(score).value = s;
	}

	fd.field('Communication').$on('change', function() {
      setScore('Communication', 'Communication_x0020_Score', 'Personal_x0020_Score');
    });


	fd.field('Employee').$on('change', function(value) {
		fd.field('Title').value = value.DisplayText;
	});

	
});
1 Like

Thank you so much! Plumsail customer services is always so helpful. Thank you for your help and for your products.

1 Like