- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 07:43 AM - edited ‎07-09-2025 07:47 AM
I have a requirement to add a UI button to create new user on Incident table.
When user click on the button,Ui page should have fields Name and email as input
When user provide these details then user record has to be created in User table
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2025 10:29 AM - edited ‎07-10-2025 10:31 AM
Try this, you can add more fields.
Accept it as solution if your query is answered.
---
UI Action
```javascript
client: true
onClick: showDialog();
function showDialog() {
var dialog = new GlideModal("create_user_from_incident");
dialog.setTitle('Create User');
dialog.setPreference('sysparm_sysid', g_form.getUniqueValue().toString());
dialog.render();
}
```
---
UI Page: `create_user_from_incident`
HTML / Jelly
```xml
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_sysid" expression="RP.getWindowProperties().get('sysparm_sysid')" />
<style>
.form-container {
width: 420px;
margin: 40px auto;
padding: 25px;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
font-family: Arial, sans-serif;
}
.form-container h2 { text-align: center; margin-bottom: 20px; }
.form-container table { width: 100%; }
.form-container td { padding: 10px; }
.form-container label { font-weight: bold; }
.form-container input[type="text"] {
width: 100%; padding: 8px;
border: 1px solid #ccc; border-radius: 4px;
}
.form-container .button-row { text-align: center; margin-top: 20px; }
.message-box {
width: 420px;
margin: 20px auto;
text-align: center;
font-weight: bold;
color: green;
}
</style>
<!-- Optional success message -->
<!--
<j:if test="${!empty(jvar_result)}">
<div class="message-box">
<g:no_escape>${jvar_result}</g:no_escape>
</div>
</j:if>
-->
<div class="form-container">
<h2>Create New User</h2>
<g:ui_form>
<input name="doc_sys_id" type="hidden" value="${jvar_sysid}" />
<table>
<tr>
<td><label for="user_name">Name:</label></td>
<td><input type="text" name="user_name" id="user_name" value="${RP.getParameter('user_name')}" /></td>
</tr>
<tr>
<td><label for="user_email">Email:</label></td>
<td><input type="text" name="user_email" id="user_email" value="${RP.getParameter('user_email')}" /></td>
</tr>
</table>
<div class="button-row">
<g:dialog_buttons_ok_cancel ok="return true;" ok_type="submit" cancel_type="button" />
</div>
</g:ui_form>
</div>
</j:jelly>
```
---
Processing Script:
```javascript
var name = request.getParameter("user_name");
var email = request.getParameter("user_email");
var document_sys_id = doc_sys_id;
gs.info('test ' + document_sys_id);
if (!gs.nil(name) || !gs.nil(email)) {
if (gs.nil(name) || gs.nil(email)) {
jvar_result = "Both Name and Email are required.";
} else {
var userGR = new GlideRecord("sys_user");
userGR.addQuery("email", email);
userGR.query();
if (userGR.next()) {
jvar_result = "A user with this email already exists: " + userGR.getDisplayValue("name");
} else {
var newUser = new GlideRecord("sys_user");
newUser.initialize();
newUser.name = name;
newUser.email = email;
newUser.user_name = email.split('@')[0];
newUser.insert();
jvar_result = "User <b>" + name + "</b> created successfully.";
}
}
if (!gs.nil(document_sys_id)) {
var redirect = gs.getProperty('glide.servlet.uri') + 'incident.do?sys_id=' + document_sys_id;
response.sendRedirect(redirect);
}
}
```
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2025 05:14 AM
Hi @Abhishek8 Did you try this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2025 06:47 PM
hi @Abhishek8 ,
First, you can add a UI Action (button) on the Incident table. This button will open a custom UI Page where users can enter the new user's name and email. The UI Action type should be Form Button, so it appears on the Incident form.
Next, create a UI Page that shows a simple form with fields for "Name" and "Email". This UI Page will also have a "Submit" button. When the user fills in these details and clicks Submit, the UI Page will call a server-side script (using GlideRecord) to insert a new record into the User (sys_user) table.
var newUser = new GlideRecord('sys_user');
newUser.initialize();
newUser.name = gs.getParameter('name');
newUser.email = gs.getParameter('email');
newUser.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2025 08:25 PM
is this a business requirement or for your learning purpose?
If it's for business requirement then this is not a valid business use-case and please inform this to customer
If this is for learning purpose then you can use UI pages for this
GlideDialogWindow: Advanced Popups Using UI Pages
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-10-2025 08:57 PM
Can you please provide the details on this,I am not much familiar with UI pages
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2025 05:37 AM
Sorry but you didn't answer my question.
I already shared my thoughts above and the link for help.
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