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  

Need help on refreshing the widget and to stay on same page. Also, to have the sysid

DB1
Tera Contributor

 

Hello All,

Need help on below two things

1. I have a custom widget created. Need help on how to refresh/ reload the page and stay on the same page and display an Info Message.

I have a form and once I submit that it is redirecting to Page not found instead I want it to stay on same page

DB1_1-1665066318190.png

 

 

DB1_0-1665066283097.png

 

Attaching the code below

 

<div class="modal" tabindex="-1" role="dialog" id="addUserForm">
<div class="modal-dialog"  role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Add New Users</h3>
</div>
<div class="modal-body">
<form action="/action_page.php" class="form-container">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label for="firstname"><b>First Name</b></label> 
<input type="text" placeholder="Enter First Name" class="form-control" name="firstname" required ng-model = "n.firstname"> 
</div>
</div>

<div class="col-xs-6">
<div class="form-group">
<label for="lastname"><b>Last Name</b></label> 
<input type="text" placeholder="Enter Last Name"class="form-control" name="lastname" required ng-model = "n.lastname">
</div>
</div>

<div class="col-xs-6">
<div class="form-group">
<label for="title"><b>Title</b></label> 
<input type="text" placeholder="Enter Title" class="form-control" name="title" required>
</div>
</div>

<div class="col-xs-6">
<div class="form-group">
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" class="form-control" name="email" required ng-model = "n.email">
</div>
</div>

</div>
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label for="busphone"><b>Business Phone</b></label> 
<input type="text" placeholder="Enter Business Phone" class="form-control" name="busphone" required>
</div>
</div>

<div class="col-xs-6">
<div class="form-group">                    
<label for="mobphone"><b>Mobile Phone</b></label> 
<input type="text" placeholder="Enter Mobile Phone" class="form-control" name="mobphone"> 
</div>
</div>

<div class="col-xs-6">
<div class="form-group">                    
<label for="country"><b>Country</b></label> 
<input type="reference" placeholder="Enter Country" class="form-control" name="country" required> 
</div>
</div>

<div class="col-xs-6">
<div class="form-group">                    
<label for="city"><b>City</b></label> 
<input type="reference" placeholder="Enter City" class="form-control" name="city" required> 
</div>
</div>

</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" ng-click="c.updateUser(n)">Submit</button>
<button type="button" class="btn cancel" ng-click="c.closeaddUserform(close)">Close</button>
</div>

</form>

</div>
</div>
</div>
</div>

 

 

client controller

 

c.updateUser=function(n){
console.log(n.email);
c.data.firstname=n.firstname;
c.data.lastname =n.lastname;
c.data.email =n.email;
c.data.action = 'create';
c.server.update();
}

 

2) second requirement

I have a server script to insert new User record. How do I get the sys id of the user record that was just inserted

 

Server script

f(input && input.action=='create')
{
//gs.addInfoMessage(input.firstname);
//gs.addInfoMessage(input.lastname);
var grUser1 = new GlideRecord('sys_user');
grUser1.addQuery('email',input.email);
if(grUser1.next())
{
gs.addInfoMessage("User already exists");
return false;
}

else{

var grUser = new GlideRecord('sys_user');
grUser.initialize(); 
grUser.first_name = input.firstname; 
grUser.last_name = input.lastname; 
grUser.email=input.email;
grUser.user_name=input.email;
grUser.password_needs_reset = true;
var sysId = grUser.insert();
gs.log("New sys id " +sysId);


var graddexuser = new GlideRecord('cmdb_rel_person');
graddexuser.initialize(); 
graddexuser.user = grUsersysId;
graddexuser.ci = Ci_id;
graddexuser.insert();
}
}

 

TIA

2 REPLIES 2

Mike_R
Kilo Patron
Kilo Patron

I don't think there is a need for a complex custom solution like this. Just create a record producer instead of a custom widget. You can then embed the RP into a modal. The less technical debt the better.

DB1
Tera Contributor

Actually this is fully customised. Can you help with refreshing the widget at least