Error declaring the client controller "Unexpected token (", "c is not defined"

Hugo Gomes
Kilo Guru

Hi everyone,

I'm having an issue with a creation of a widget in Service Portal.

It is throwing an error, "c is not defined", and when visualizing the code in the editor, in the first line, the declaration of the function is showing "Unexpected token (".

This was not an issue in previous ServiceNow releases.

Client controller

function ($scope, spUtil, $uibModal) {

	spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);
  /* widget controller */
	var modalInstance;
	var c = this;
	c.uiAction = function(action) {
		c.data.action = action;
		c.server.update().then(function() {
			c.data.action = undefined;
		})
	};
	$scope.$on('record.updated', function(name, data) {
	
	//c.data.reopenComments = '';
    spUtil.update($scope);
		modalInstance.dismiss();
  });
	
	c.openModalSignature = function() {
		modalInstance = $uibModal.open({
		templateUrl: 'modalTemplateSignature.html',
		scope: $scope
	});
	};
}

Has anything changed in this release in regards to AngularJS and in the way we should declare the client controller?

If anyone helps me I would much appreciate it 🙂

 

Regards

Hugo Gomes

1 ACCEPTED SOLUTION

DrewW
Mega Sage
Mega Sage

So some thoughts on troubleshooting.  Comment out all of the code in the function(s) and see if the issue goes away.  If not keep commenting things out until it does.  That should tell you where.  If commenting out the code in a function causes it to go away start uncommenting them one line at a time until it comes back.  That should give you something to look at.

But if you look at the error it says "Server JavaScript error "c" is not defined."  It looks to me you posted the client side code not the server code.  In my experience c is not declared in the server code only client side.

 

 

View solution in original post

7 REPLIES 7

DrewW
Mega Sage
Mega Sage

So some thoughts on troubleshooting.  Comment out all of the code in the function(s) and see if the issue goes away.  If not keep commenting things out until it does.  That should tell you where.  If commenting out the code in a function causes it to go away start uncommenting them one line at a time until it comes back.  That should give you something to look at.

But if you look at the error it says "Server JavaScript error "c" is not defined."  It looks to me you posted the client side code not the server code.  In my experience c is not declared in the server code only client side.

 

 

Hugo Gomes
Kilo Guru

The issue was on the Server Script.

 

Thank you very much

Dharmit Prajap1
Kilo Contributor

What did you change in the server script to get rid of the error?