Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Display message on a portal page

Shuto Sato
Tera Expert

Hello everyone,


I have a requirement to display a message on the “csm_contact” page when a user clicks on the Disable Login / Enable Login link, similar to when g_form.addInfoMessage() is used in a Catalog Item.
I have tried adding gs.addInfoMessage() and g_form.addInfoMessage() in the Client controller of the widget that cloned the “Contact Roles” widget, but no message is displayed.


Here is the code I tried.

function ($scope, $uibModal, $window, spAriaUtil, $timeout) {
	var c = this;
	var instance;
	
	$scope.editRoles = function() {
		$scope.modalInstance = $uibModal.open({
			templateUrl: 'addContactRoleModal',
			size: 'lg',
			scope: $scope
		});
		$scope.modalInstance.rendered.then(function() {
			var modal = $('div.modal');
			modal.attr('aria-labelledby','modal-title');
			modal.find('#closeContactRoleModal').focus();
		});
	};
	
	c.lock = function(lock) {
		g_form.addInfoMessage('Example Text'); // Added code
		$scope.data.action = 'lock';
		$scope.data.lock = lock;
		$scope.server.update().then(function(response) {
			if(response.status == 'success') {
				var infoMessage = lock? "${Login disabled}": "${Login enabled}";
				var focusLinkId = lock? "enable_login": "disable_login"
				spAriaUtil.sendLiveMessage(infoMessage);
				$timeout(function() {
					$("#" + focusLinkId).focus();
				}, 1000);
			}
		});
	};
	
	c.cancel = function() {
		$window.location.reload();
		$scope.modalInstance.close();		
	};
}

 

Is there any way to implement the above requirements?
Any advice is welcome.

 

Best regards,
Shuto

1 ACCEPTED SOLUTION

Deepak Negi
Mega Sage
Mega Sage

try $scope.page.g_form.addInfoMessage in client controller.

or

try gs.addInfoMessage() in server script

View solution in original post

2 REPLIES 2

Deepak Negi
Mega Sage
Mega Sage

try $scope.page.g_form.addInfoMessage in client controller.

or

try gs.addInfoMessage() in server script

Hi Deepak

 

Thanks for the quick reply.

gs.addInfoMessage() in server script worked fine.
The $scope.page.g_form.addInfoMessage in client controller caused an error.

However, I noticed that by adding spUtil as an argument, the message can also be displayed from the client controller.
I am attaching the code as well so that anyone who stumbles as I did can refer to it.

function ($scope, $uibModal, $window, spAriaUtil, $timeout, spUtil) {	// spUtil added
	var c = this;
	var instance;
	
	$scope.editRoles = function() {
		$scope.modalInstance = $uibModal.open({
			templateUrl: 'addContactRoleModal',
			size: 'lg',
			scope: $scope
		});
		$scope.modalInstance.rendered.then(function() {
			var modal = $('div.modal');
			modal.attr('aria-labelledby','modal-title');
			modal.find('#closeContactRoleModal').focus();
		});
	};
	
	c.lock = function(lock) {
		spUtil.addInfoMessage('### Example Text ###');	// Added code
		$scope.data.action = 'lock';
		$scope.data.lock = lock;
		$scope.server.update().then(function(response) {
			if(response.status == 'success') {
				var infoMessage = lock? "${Login disabled}": "${Login enabled}";
				var focusLinkId = lock? "enable_login": "disable_login"
				spAriaUtil.sendLiveMessage(infoMessage);
				$timeout(function() {
					$("#" + focusLinkId).focus();
				}, 1000);
			}
		});
	};
	
	c.cancel = function() {
		$window.location.reload();
		$scope.modalInstance.close();		
	};
}