The CreatorCon Call for Content is officially open! Get started here.

How to show different containers that contains different form on widget based on loggedin users

DB1
Tera Contributor

 

 

 

 

Hi All,

 

I have a widget that loads on a Portal Page.

Page name - Contact list page and it has a widget.

 

That widget has 2 containers with 2 different forms and fields.

Example

 

 

<div id="contactlistform1" ng-show="c.frm1">
			  
			  <div class="row">
                  <div class="col-xs-6">
                    <div class="form-group">
                      <label for="PUseremail"><b>Email</b><span class="fa fa-asterisk mandatory"></span></label>
                      <input type="text" placeholder="Enter Email" class="form-control" name="PUseremail" ng-model="c.addUsr.PUseremail" required>
                      <span class="error" style="display : none;color:#ff0000;" id="PUseremail">{{c.errMsg.emailerror}}</span>                  
                    </div>
                  </div>
				  </div>

<!-- Form 2-->

<div id="contactlistform2" ng-show="c.frm2">
			  
			  <div class="row">
                  <div class="col-xs-6">
                    <div class="form-group">
                      <label for="name"><b>Name</b><span class="fa fa-asterisk mandatory"></span></label>
                      <input type="text" placeholder="Enter Name" class="form-control" name="name" ng-model="c.addUsr.name" required>
                      <span class="error" style="display : none;color:#ff0000;" id="name">{{c.errMsg.emailerror}}</span>                  
                    </div>
                  </div>
				  </div>
</div>
</div>

 

Now the req is to show the form 1 - contactlistform1 only if the logged in user does have "franco" in the domain on email.

 

Meaning:

 

 

Var grcheckuser = new GlideRecord('sys_user');
grcheckuser.addQuery('sys_id',gs.getLoggedInuser());
grcheckuser.query();
if(grcheckuser.next()
{
var email = grcheckuser.email();
if(email.indexOf('franco'))
{
return true; // This has to be passed to client side/ html and if this condition is returned it has to show form 1
}
else
{
return false; // this has to show form2
}
}

 

 

Can someone help to achieve this?

 

@Dr Atul G- LNG @Danish Bhairag2 @Mark Manders @James Chun @Harish KM 

TIA.

 

1 REPLY 1

Anirudh Pathak
Mega Sage

Hi @DB1 ,

Please use the below codes - 

 

HTML - 

<div id="contactlistform1" ng-show="c.frm1">
			  
			  <div class="row">
                  <div class="col-xs-6">
                    <div class="form-group">
                      <label for="PUseremail"><b>Email</b><span class="fa fa-asterisk mandatory"></span></label>
                      <input type="text" placeholder="Enter Email" class="form-control" name="PUseremail" ng-model="c.addUsr.PUseremail" required>
                      <span class="error" style="display : none;color:#ff0000;" id="PUseremail">{{c.errMsg.emailerror}}</span>                  
                    </div>
                  </div>
				  </div>
</div>
<!-- Form 2-->

<div id="contactlistform2" ng-show="c.frm2">
			  
			  <div class="row">
                  <div class="col-xs-6">
                    <div class="form-group">
                      <label for="name"><b>Name</b><span class="fa fa-asterisk mandatory"></span></label>
                      <input type="text" placeholder="Enter Name" class="form-control" name="name" ng-model="c.addUsr.name" required>
                      <span class="error" style="display : none;color:#ff0000;" id="name">{{c.errMsg.emailerror}}</span>                  
                    </div>
                  </div>
	         </div>
</div>

 

Server Side - 

(function() {
        /* populate the 'data' object */
        /* e.g., data.table = $sp.getValue('table'); */
		data.userCheck = '';
        var grcheckuser = new GlideRecord('sys_user');
        grcheckuser.addQuery('sys_id', gs.getUserID());
        grcheckuser.query();
        if (grcheckuser.next()) {
                var email = grcheckuser.email.toString();
                if (email.indexOf('franco') > 0) {
                   data.userCheck = 'yes'; // This has to be passed to client side/ html and if this condition is returned it has to show form 1
                } else {
                   data.userCheck = 'no'; // this has to show form2
                }
            }
		

        })();

 

Client Controller -

api.controller=function() {
  /* widget controller */
  var c = this;
  c.frm1 ='';
  c.frm2 = '';
  if(c.data.userCheck == 'yes') {
	c.frm1 = true;
	c.frm2 = false;
  }
  else {
	c.frm2 = true;
	c.frm1 = false;
  }
};