error message on client controller "It should contain a JavaScript function"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2021 07:47 PM
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');
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2021 08:50 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2021 09:28 PM
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)"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2021 09:34 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2021 10:19 PM