Show Modal on load based on condition Custom Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2023 08:29 AM
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">×</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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2023 08:49 AM
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();
};
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2023 09:03 AM
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