error message on client controller "It should contain a JavaScript function"

TMKAM
Tera Contributor

I receive an error on when i try to save a newly created widget at service portal and this error is on client controller with message "It should contain a JavaScript function"

here are the scripts in client controller and thank you for your solution.

function($scope, $rootScope, spUtil) {
/* widget controller */
var c = this;

$scope.uploading = false;
$scope.parent = getParent($scope);
$scope.no_attachments = $scope.parent.c.data.sc_cat_item.no_attachments;
$scope.mandatory_attachment = $scope.parent.c.data.sc_cat_item.mandatory_attachment;

$rootScope.$on("attachment.upload.start", function(x,y){
$scope.uploading = true;
});

$rootScope.$on("attachment.upload.stop", function(x,y){
$scope.uploading = false;
});

$scope.attachmentHandler = $scope.parent.attachmentHandler;
$scope.confirmDeleteAttachment = $scope.parent.confirmDeleteAttachment;

$scope.attachments = [];
$scope.$watch('parent.attachments',function(){
if ($scope.parent.attachments) {
$scope.attachments = $scope.parent.attachments;
}
})

$scope.mandatory_filled = function() {
return ($scope.attachments.length > 0);
}

function getParent(parent) {
if (parent.item) {
if (parent.widget.id != "widget-sc-cat-item-v2")
//BBraun adjustment: No error message because we are using a custom widget for catalog item display
//spUtil.addErrorMessage("The catalog attachments widget is only compatible with 'widget-sc-cat-item-v2'");
return parent;
} else {
if (parent.$parent){
return getParent(parent.$parent);
} else {
spUtil.addErrorMessage("An error has occured");
console.warn('Was not able to find parent widget');
}
}
}

}

6 REPLIES 6

Omkar Mone
Mega Sage

Hello,

Can you try with the below updated block?

(function($scope, $rootScope, spUtil) {
	/* widget controller */
	var c = this;

	$scope.uploading = false;
	$scope.parent = getParent($scope);
	$scope.no_attachments = $scope.parent.c.data.sc_cat_item.no_attachments;
	$scope.mandatory_attachment = $scope.parent.c.data.sc_cat_item.mandatory_attachment;

	$rootScope.$on("attachment.upload.start", function(x,y){
		$scope.uploading = true;
	});

	$rootScope.$on("attachment.upload.stop", function(x,y){
		$scope.uploading = false;
	});

	$scope.attachmentHandler = $scope.parent.attachmentHandler;
	$scope.confirmDeleteAttachment = $scope.parent.confirmDeleteAttachment;

	$scope.attachments = [];
	$scope.$watch('parent.attachments',function(){
		if ($scope.parent.attachments) {
			$scope.attachments = $scope.parent.attachments;
		}
	})

	$scope.mandatory_filled = function() {
		return ($scope.attachments.length > 0);
	}

	function getParent(parent) {
		if (parent.item) {
			if (parent.widget.id != "widget-sc-cat-item-v2")
				//BBraun adjustment: No error message because we are using a custom widget for catalog item display
				//spUtil.addErrorMessage("The catalog attachments widget is only compatible with 'widget-sc-cat-item-v2'");
				return parent;
		} else {
			if (parent.$parent){
				return getParent(parent.$parent);
			} else {
				spUtil.addErrorMessage("An error has occured");
				console.warn('Was not able to find parent widget');
			}
		}
	}

});

 

Regards,

Omkar

TMKAM
Tera Contributor

after i copy and paste your scripts another error shown

 

"Could not save record because of a compile error: JavaScript parse error at line (49) column (1) problem = missing ) in parenthetical (<refname>; line 49)"

Hello 

Can you try this once - 

api.controller=function($scope, $rootScope, spUtil) {
	/* widget controller */
	var c = this;

	$scope.uploading = false;
	$scope.parent = getParent($scope);
	$scope.no_attachments = $scope.parent.c.data.sc_cat_item.no_attachments;
	$scope.mandatory_attachment = $scope.parent.c.data.sc_cat_item.mandatory_attachment;

	$rootScope.$on("attachment.upload.start", function(x,y){
		$scope.uploading = true;
	});

	$rootScope.$on("attachment.upload.stop", function(x,y){
		$scope.uploading = false;
	});

	$scope.attachmentHandler = $scope.parent.attachmentHandler;
	$scope.confirmDeleteAttachment = $scope.parent.confirmDeleteAttachment;

	$scope.attachments = [];
	$scope.$watch('parent.attachments',function(){
		if ($scope.parent.attachments) {
			$scope.attachments = $scope.parent.attachments;
		}
	})

	$scope.mandatory_filled = function() {
		return ($scope.attachments.length > 0);
	}

	function getParent(parent) {
		if (parent.item) {
			if (parent.widget.id != "widget-sc-cat-item-v2")
				//BBraun adjustment: No error message because we are using a custom widget for catalog item display
				//spUtil.addErrorMessage("The catalog attachments widget is only compatible with 'widget-sc-cat-item-v2'");
				return parent;
		} else {
			if (parent.$parent){
				return getParent(parent.$parent);
			} else {
				spUtil.addErrorMessage("An error has occured");
				console.warn('Was not able to find parent widget');
			}
		}
	}

};

 

Regards,

Omkar

TMKAM
Tera Contributor

i paste the new scripts and receive error message "It should contain a JavaScript function" and the screenshot for your reference.