- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 07:40 AM
Hi All,
We've been asked to create a ui action to close duplicate tickets in the incident table but when closed the advisor should be prompted to input the parent request ticket number if it's empty.
I've looked around and found various ways to do this but was hoping to seek advice here if someone has had something like this asked from their team?
I've tried using GlideModalV3 but honestly the documentation leaves much to be desired
Thanks all
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 05:29 AM
so your final code will be like this
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>
<g:evaluate var="jvar_sysid" expression="RP.getWindowProperties().get('sys_id')"/>
<input type="hidden" id="cancelled" name="cancelled" value="false"/>
<input type="hidden" id="incidentSysID" name="incidentSysID" value="${jvar_sysid}"/>
<table>
<tr>
<td id="label.parent request" class="label" nowrap="true" height="23px" type="string" choice="0"><span id="status." class="mandatory label_description" mandatory="true" oclass="mandatory">$[SP]</span><label for="parent request" onclick="" dir="">Parent Ticket:</label></td>
<td nowrap="true"><g:ui_reference name="parent_request" id="parent request" table="incident"/></td></tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr><td align="left" nowrap="true"><br /><g:dialog_buttons_ok_cancel ok="return validateForm();" 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 validateForm() {
alert('inside validateform');
if (gel('parent_request').value == '') {
alert("${JS:gs.getMessage('Please input Parent Ticket')}");
return false;
}
else {
var sysId = gel('incidentSysID').value;
var parentValue = gel('parent_request').value;
var app = new GlideRecord("incident");
if(app.get(sysId)){
app.parent_request = parentValue;
app.incident_state = '7';
app.work_notes = "Closed as Duplicate";
app.close_code = "Duplicate Call";
app.close_notes = "Closed as Duplicate";
app.state = '7';
app.update();
}
window.open('/incident.do?sys_id='+sysId,'_self');
}
}
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
09-09-2022 02:27 AM
Thanks
so it looks like from the alert debugging the issue lies with the value for sysId
it doesn't appear to be pulling through the sys_id from the original ticket
the parent_request value is passing correctly and i've tested adding the parent_request value to the end of the window.open and this did open the ticket i was trying to add to the field so it is picking up the correct parent_request it just seems to not be picking up the sys_id from the ticket opened on
I've noticed this strange bug where the type and item values are changing after the the process has completed....the values are the sysid of the ticket being viewed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 02:32 AM
Hi,
so it means the sys_id of the record from where the button was clicked is not sent correctly or fetched correctly
Did you update the UI action code as per what I said?
UI Action:
function commentsDialog() {
var gm = new GlideModal('Add Parent Reference');
gm.setTitle('Show title');
gm.setPreference('sys_id', g_form.getUniqueValue());
gm.render();
}
Small update in 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>
<g:evaluate var="jvar_sysid" expression="RP.getWindowProperties().sys_id"/>
<input type="hidden" id="cancelled" name="cancelled" value="false"/>
<input type="hidden" id="incidentSysID" name="incidentSysID" value="${jvar_sysid}"/>
<table>
<tr>
<td id="label.parent request" class="label" nowrap="true" height="23px" type="string" choice="0"><span id="status." class="mandatory label_description" mandatory="true" oclass="mandatory">$[SP]</span><label for="parent request" onclick="" dir="">Parent Ticket:</label></td>
<td nowrap="true"><g:ui_reference name="parent_request" id="parent request" table="incident"/></td></tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr><td align="left" nowrap="true"><br /><g:dialog_buttons_ok_cancel ok="return validateForm();" cancel="return onCancel();"/></td></tr>
</table>
</g:ui_form>
</j:jelly>
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
09-09-2022 03:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 03:33 AM
EDIT: the sysid being populated is for the ui page not the ticket ref 😞
======
i replaced
<g:evaluate var="jvar_sysid" expression="RP.getWindowProperties().sys_id"/>
with
<g:evaluate var="jvar_sysid" expression ="RP.getParameterValue('sys_id')" />
just one last thing now where the parent request field is still not populating on the ticket
Thanks for your help with this so far wouldn't of managed any of this without your help 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 04:09 AM
Hi
Looks like it's working after tweaking the html to the following:
<?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>
<g:evaluate var="jvar_sysid" expression="RP.getWindowProperties().get('sys_id')"/>
<input type="hidden" id="cancelled" name="cancelled" value="false"/>
<input type="hidden" id="incidentSysID" name="incidentSysID" value="${jvar_sysid}"/>
<table>
<tr>
<td id="label.parent request" class="label" nowrap="true" height="23px" type="string" choice="0"><span id="status." class="mandatory label_description" mandatory="true" oclass="mandatory">$[SP]</span><label for="parent request" onclick="" dir="">Parent Ticket:</label></td>
<td nowrap="true"><g:ui_reference name="parent_request" id="parent request" table="incident"/></td></tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr><td align="left" nowrap="true"><br /><g:dialog_buttons_ok_cancel ok="return validateForm();" cancel="return onCancel();"/></td></tr>
</table>
</g:ui_form>
</j:jelly>
ironically it was yourself that provided that answer in this ticket
https://community.servicenow.com/community?id=community_question&sys_id=15849da8db4c885023f4a345ca96190b
=============
i just have some really weird things happening now if you have any idea?
when i use this function now the parent request does populate in the correct field in a new window however the previous window remains on the ui page
I've tried to get around this by amending the final line of client script with
"action.SetRedirectURL('https://"instance here".service-now.com/incident.do?sys_id='+ sysId);"
But still ui page loads
and for some reason fields are auto populating where they are empty before is very strange