Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Show spModal after entering the portal

Aurelio
Tera Contributor

Hello,

I am trying to make a "spModal" window appear when entering the portal, this window should be shown only if the user has pending surveys and when clicking the "Ir a encuesta" button, it directs me to the page "my_surveys", please one suggestion.

 

This is my code,

HTML:

<div>
<button class="btn btn-primary" ng-click="c.openModal()">${Open Modal}</button>
</div>

<script type="text/ng-template" id="modalTemplate">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Modal Window</h4>
</div>
<div class="panel-body wrapper-xl">
Tiene encuestas pendientes!!
</div>
<div class="panel-footer text-right">
<button class="btn btn-primary" ng-click="c.closeModal()">${Recordar mas tarde}</button>
<button class="btn btn-primary" ng-click="c.closeModal()">${Ir a encuesta}</button>
</div>
</div>
</script>

CLIENT SCRIPT:

function($uibModal, $scope) {
var c = this;

c.openModal = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate',
scope: $scope
});
}

c.closeModal = function() {
c.modalInstance.close();
}

}

1 ACCEPTED SOLUTION

Hey Aurelio, sorry about the delay. The server side script would look something like this. 

I tested this in my personal instance and it works. 

(function() {

var loggedInUser = gs.getUserID();
	data.check = checkForSurvey(loggedInUser);

})();


function checkForSurvey(user){
	
	var gr = new GlideRecord('asmt_assessment_instance');
		gr.addQuery("metric_type.active", true);
		gr.addQuery("metric_type.publish_state", "published");
		gr.addQuery("preview", false);
		gr.addQuery('user', user);
		var sub = gr.addQuery('state', 'ready');
		sub.addOrCondition('state','wip');
		gr.query();
	if(gr.next())
		return true;
	else
		return false;
	
}

 

Then your next step would be to add an 'IF' statement in your client script. something like 

if(c.data.check == true){

do the popup

}

else

do nothing

 

View solution in original post

6 REPLIES 6

Hey Aurelio, sorry about the delay. The server side script would look something like this. 

I tested this in my personal instance and it works. 

(function() {

var loggedInUser = gs.getUserID();
	data.check = checkForSurvey(loggedInUser);

})();


function checkForSurvey(user){
	
	var gr = new GlideRecord('asmt_assessment_instance');
		gr.addQuery("metric_type.active", true);
		gr.addQuery("metric_type.publish_state", "published");
		gr.addQuery("preview", false);
		gr.addQuery('user', user);
		var sub = gr.addQuery('state', 'ready');
		sub.addOrCondition('state','wip');
		gr.query();
	if(gr.next())
		return true;
	else
		return false;
	
}

 

Then your next step would be to add an 'IF' statement in your client script. something like 

if(c.data.check == true){

do the popup

}

else

do nothing

 

Thank you very much for your help lgomez, I was finally able to finish the configuration for the popup window.