- 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-16-2020 05:07 AM
Hi
I need one more help in this thread.
After Incident is created successfully, the RITM state should be changed to "Awaiting Info" and also Incident number should be captured in a field in RITM Table.
I tried this by putting current.state = "awaiting_info" in UI action but it is not working.
Should I have to write a seperate business rule to update the state value and Incident number field in RITM table? or is there any way to do it in the UI page itself?
Best Regards,
Ram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2020 08:19 AM
Hi,
You can handle this in processing script itself.
Refer below updated logic
var gr = new GlideRecord("incident");
gr.initialize();
gr.<source_field> = ritmSysId;
gr.comments = comments;
gr.setDisplayValue('assignment_group','Service Desk'); // for example purpose
var incSysId = gr.insert();
var ritm = new GlideRecord('sc_req_item');
ritm.get(ritmSysId);
ritm.<incident_field> = incSysId; // give here the field which holds INC
// if the custom field is string then use the below line
ritm.<incident_field> = gr.number;
ritm.state = 'awaiting_info';
ritm.update();
//response.sendRedirect('incident.do?sys_id='+task_sys_id);
var urlOnStack = gs.getUrlOnStack();
response.sendRedirect(urlOnStack);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader