- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2025 11:28 PM
How can I register a new user from Service Portal and store their password in the sys_user table so that they can log in to the portal?
I have created a custom registration widget/form in the Service Portal that collects:
1.Full Name
2.Email
3.Username
4.Password
I want the submitted data to create a new record in the sys_user table, and set the password so the user can immediately log in to the portal
As Of now I have tried using custom Widget to create a new user record to login service portal:
Data is getting stored in user table but login is not working
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2025 11:40 PM
Hi @Rajkumar Bommal ,
Refer to this thread: Solved: how to include user registration feature in my ser... - ServiceNow Community
You can watch this video :Plan your retirement better with Axis Max Life Insurance
Sandeep Dutta
Please mark the answer correct & Helpful, if i could help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2025 02:29 AM
Hi @Rajkumar Bommal ,
try with this foloowing code
html
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" ng-model="c.data.first_name" />
</div>
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" ng-model="c.data.last_name" />
</div>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" ng-model="c.data.email" />
</div>
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" ng-model="c.data.username" />
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" ng-model="c.data.password" />
</div>
<button class="btn btn-primary" ng-click="c.register()">Register</button>
<div class="alert alert-success" ng-if="c.data.success">
{{c.data.message}}
</div>
<div class="alert alert-danger" ng-if="c.data.error">
{{c.data.message}}
</div>
client script
function($scope) {
var c = this;
c.register = function() {
c.server.get({
action: "register",
first_name: c.data.first_name,
last_name: c.data.last_name,
email: c.data.email,
username: c.data.username,
password: c.data.password
}).then(function(response) {
c.data.success = response.data.success;
c.data.error = response.data.error;
c.data.message = response.data.message;
});
};
}
Server script
(function() {
if (input && input.action === "register") {
// Check if user already exists
var existingUser = new GlideRecord('sys_user');
existingUser.addQuery('user_name', input.username);
existingUser.query();
if (existingUser.next()) {
data.success = false;
data.error = true;
data.message = 'Username already exists';
return;
}
// Check if email already exists
var existingEmail = new GlideRecord('sys_user');
existingEmail.addQuery('email', input.email);
existingEmail.query();
if (existingEmail.next()) {
data.success = false;
data.error = true;
data.message = 'Email already registered';
return;
}
// Create new user
var newUser = new GlideRecord('sys_user');
newUser.initialize();
newUser.first_name = input.first_name;
newUser.last_name = input.last_name;
newUser.email = input.email;
newUser.user_name = input.username;
newUser.user_password.setDisplayValue(input.password); // Proper password handling
newUser.active = true;
var userSysId = newUser.insert();
if (userSysId) {
data.success = true;
data.error = false;
data.message = 'Registration successful! You can now login.';
} else {
data.success = false;
data.error = true;
data.message = 'Registration failed. Please try again.';
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2025 02:29 AM
Hi @Rajkumar Bommal ,
try with this foloowing code
html
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" ng-model="c.data.first_name" />
</div>
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" ng-model="c.data.last_name" />
</div>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" ng-model="c.data.email" />
</div>
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" ng-model="c.data.username" />
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" ng-model="c.data.password" />
</div>
<button class="btn btn-primary" ng-click="c.register()">Register</button>
<div class="alert alert-success" ng-if="c.data.success">
{{c.data.message}}
</div>
<div class="alert alert-danger" ng-if="c.data.error">
{{c.data.message}}
</div>
client script
function($scope) {
var c = this;
c.register = function() {
c.server.get({
action: "register",
first_name: c.data.first_name,
last_name: c.data.last_name,
email: c.data.email,
username: c.data.username,
password: c.data.password
}).then(function(response) {
c.data.success = response.data.success;
c.data.error = response.data.error;
c.data.message = response.data.message;
});
};
}
Server script
(function() {
if (input && input.action === "register") {
// Check if user already exists
var existingUser = new GlideRecord('sys_user');
existingUser.addQuery('user_name', input.username);
existingUser.query();
if (existingUser.next()) {
data.success = false;
data.error = true;
data.message = 'Username already exists';
return;
}
// Check if email already exists
var existingEmail = new GlideRecord('sys_user');
existingEmail.addQuery('email', input.email);
existingEmail.query();
if (existingEmail.next()) {
data.success = false;
data.error = true;
data.message = 'Email already registered';
return;
}
// Create new user
var newUser = new GlideRecord('sys_user');
newUser.initialize();
newUser.first_name = input.first_name;
newUser.last_name = input.last_name;
newUser.email = input.email;
newUser.user_name = input.username;
newUser.user_password.setDisplayValue(input.password); // Proper password handling
newUser.active = true;
var userSysId = newUser.insert();
if (userSysId) {
data.success = true;
data.error = false;
data.message = 'Registration successful! You can now login.';
} else {
data.success = false;
data.error = true;
data.message = 'Registration failed. Please try again.';
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2025 03:34 AM
Usually user table is populated via AD/LDAP integration.
Unless you are using CSM ideally you should not allow direct user creation.
When it comes to CSM it's a self-registration process but it's on esc portal.
what's your exact business requirement?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2025 04:32 AM
Did you explore:
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************