We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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

AnirudhKumar
Mega Sage

Your getParent() function is not properly defined.

Do it this way:

$scope.getParent = function()
{

}

if i replace "function getParent(parent) {" to "$scope.getParent = function()" i receive error message "Could not save record because of a compile error: JavaScript parse error at line (33) column (5) problem = missing { before function body (<refname>; line 33)"