- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 05:48 AM
I have a requirement to create a new Incident by clicking on UI Action "Create Incident" from RITM form. While clicking on "Create Incident", a pop up opens and prompt the user to enter the comment and click OK. After clicking OK the new Incident has to be created. I have created UI action, UI Page in screenshot.
Help need to write a script to populate few values (Like Assignment group, description, "Source" should be RITM number) from RITM table to Incident table. Also I have to create a many to many relationship between RITM & Incident table (Note: I don't know in which place exactly I have to write a code for new Incident initialization i.e.. in UI Action or in UI page).
I referred the following links to create these
https://www.servicenowelite.com/blog/2014/2/24/copy-incident
https://www.servicenowelite.com/blog/2014/2/26/new-caller-window-dialog
https://www.servicenowguru.com/system-ui/glidedialogwindow-advanced-popups-ui-pages/
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 08:41 AM
please find the updated script; I have tested and it is working fine
UI Action:
function createIncident(){
var sysId = g_form.getUniqueValue();
var gDialog = new GlideDialogWindow('create_Incident');
gDialog.setSize('600','600');
gDialog.setPreference('sysparm_sysID', sysId);
gDialog.setTitle('Create Incident');
gDialog.render();
}
UI Page
HTML
<?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:ui_form>
<!-- Get values from dialog preferences passed in -->
<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().get('sysparm_sysID')" />
<!-- Set up form fields and labels -->
<input type="hidden" name="ritmSysId" id="ritmSysId" value="${jvar_sysId}"/>
<input type="hidden" name="comments" id="comments" value=""/>
<table width="100%">
<tr>
<td>
<!-- Comments text field (Contains comments from originating record as a default) -->
<g:ui_multiline_input_field name="dial_comments" id="dial_comments" label="Additional comments" value="${jvar_comments_text}" mandatory="true" />
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr id="dialog_buttons">
<td colspan="2" align="right">
<g:dialog_buttons_ok_cancel ok="return submitRecord();" cancel ="return OnCancel();"/>
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>
Client Script
function onCancel() {
var c = gel('cancelled');
c.value = "true";
GlideDialogWindow.get().destroy();
return false;
}
function submitRecord() {
var comments = gel("dial_comments").value;
comments = trim(comments);
if (comments == "") {
//If comments are empty stop submission
alert("Please provide comments to submit the dialog.");
return false;
}
gel("comments").value = comments;
return true;
}
Processing Script
var gr = new GlideRecord("incident");
gr.initialize();
gr.<source_field> = ritmSysId;
gr.comments = comments;
gr.setDisplayValue('assignment_group','Service Desk'); // for example purpose
gr.insert();
//response.sendRedirect('incident.do?sys_id='+task_sys_id);
var urlOnStack = gs.getUrlOnStack();
response.sendRedirect(urlOnStack);
UI Action:
Regards
Ankur
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-15-2020 05:58 AM
Hi,
Few things to check/inform
1) you need to populate the extra fields from the UI page processing script
2) Is source field on Incident a custom one? What is it's type? reference or glide list?
a) if it is reference then it can hold only 1 RITM
b) if it is list then it can hold more than 1 RITMs
3) If yes then you can have defined relationship created based on the source field type
4) On RITM form you can show incidents
5) On incident form you can show RITM
It would be nice if you share the script here; it's difficult to write from image
Regards
Ankur
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-15-2020 06:18 AM
Hi Ankur,
Thanks for your reply.
1. Okay, please give me an example how I can populate a field from RITM to Incident via processing script. Let's take Assignment group field for this instance.
2. Source field is a custom reference field.
3. Okay I will create a relationship seperately
Attaching all the scripts in notepad.
Best Regards,
Ram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 08:41 AM
please find the updated script; I have tested and it is working fine
UI Action:
function createIncident(){
var sysId = g_form.getUniqueValue();
var gDialog = new GlideDialogWindow('create_Incident');
gDialog.setSize('600','600');
gDialog.setPreference('sysparm_sysID', sysId);
gDialog.setTitle('Create Incident');
gDialog.render();
}
UI Page
HTML
<?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:ui_form>
<!-- Get values from dialog preferences passed in -->
<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().get('sysparm_sysID')" />
<!-- Set up form fields and labels -->
<input type="hidden" name="ritmSysId" id="ritmSysId" value="${jvar_sysId}"/>
<input type="hidden" name="comments" id="comments" value=""/>
<table width="100%">
<tr>
<td>
<!-- Comments text field (Contains comments from originating record as a default) -->
<g:ui_multiline_input_field name="dial_comments" id="dial_comments" label="Additional comments" value="${jvar_comments_text}" mandatory="true" />
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr id="dialog_buttons">
<td colspan="2" align="right">
<g:dialog_buttons_ok_cancel ok="return submitRecord();" cancel ="return OnCancel();"/>
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>
Client Script
function onCancel() {
var c = gel('cancelled');
c.value = "true";
GlideDialogWindow.get().destroy();
return false;
}
function submitRecord() {
var comments = gel("dial_comments").value;
comments = trim(comments);
if (comments == "") {
//If comments are empty stop submission
alert("Please provide comments to submit the dialog.");
return false;
}
gel("comments").value = comments;
return true;
}
Processing Script
var gr = new GlideRecord("incident");
gr.initialize();
gr.<source_field> = ritmSysId;
gr.comments = comments;
gr.setDisplayValue('assignment_group','Service Desk'); // for example purpose
gr.insert();
//response.sendRedirect('incident.do?sys_id='+task_sys_id);
var urlOnStack = gs.getUrlOnStack();
response.sendRedirect(urlOnStack);
UI Action:
Regards
Ankur
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-15-2020 11:49 AM