- 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-09-2025 08:04 AM
Hello!
The ui page can be also a simple popup?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2025 07:45 AM
@Abhishek8 , I have worked on similar type of thing, can you tell me which other fields of user should display in ui page?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2025 09:07 AM
First name,last name and email only
- 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);
}
}
```