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 Modal on load based on condition Custom Widget

DB1
Tera Contributor

Hello All,

I have the following requirement.

1. There is a Page "ph_poc_page1" .

When user tries to access the URL :"https://dev234354.service-now.com/sp?id=ph_poc_aws_page1

a. It should check if logged in User has CI relationship. If yes, it should show the User a Modal else it should show another Modal.

I am trying to create a Custom Widget to achieve the same however it is not working.

Please help me achieve it.

 

Below is the code 

HTML

<div>
  <div id="myModal" class="modal">

    <!-- Modal content -->
    <div class="modal-content">
      <span class="close">&times;</span>
      <p> Welcome to the I noticed\</p>
      <p>...........</p>
      <p>Please complete the form below </p>
    </div>

  </div>


</div>

 

client

api.controller=function() {
	/* widget controller */
	var c = this;
	var url="";
	c.openPopUp = function() {
		if(data.flag == "true")
		{
			$window.onload = function () {
				OpenBootstrapPopup();
			};

		}
		function OpenBootstrapPopup() {
			$("#myModal").modal('show');
		}
		if(data.flag == "false")
		{
			//url = "https://demo";
		}

	
	};


};

 

server

(function() {
	var loggedIn = gs.getUserID();
	data.flag = "";
	var grgetUser = new GlideRecord('cmdb_rel_person');
	grgetUser.addQuery('user',loggedIn);
	grgetUser.addQuery('user.active','true');
	grgetUser.query();
	if(grgetUser.next())
	
		data.flag="true";
	
	else
		
			data.flag="false";
		


})();

 

@Ankur Bawiskar @DrewW    @Chuck Tomasi @Anurag Tripathi @AndersBGS 

2 REPLIES 2

Ahmmed Ali
Giga Sage
Giga Sage

Try below client script:

api.controller=function() {
/* widget controller */
var c = this;
var url="";
c.openPopUp = function() {
if(c.data.flag == true)
{
$("#myModal").modal('show');
}
if(c.data.flag == false)
{
//url = "https://demo";
}


};

c.openPopUp();


};

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

DB1
Tera Contributor

Hi Thanks for the reply.  I tried, 

c.openPopUp = function() {
if(c.data.flag == true)
{
$("#myModal").modal('show');
}
if(c.data.flag == false)
{
//url = "https://demo";
}


};

c.openPopUp();
};

 

However not working