UI Action Prompt for User input

Sam Motley
Giga Guru

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 

1 ACCEPTED SOLUTION

@Sam Motley 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

32 REPLIES 32

@Sam Motley 

Glad that it's working

action won't work in client script

Can you share your complete UI page script and what's required to happen when OK is clicked?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar thank you 🙂 like i say there's no way i could've got this far without your help.

When OK is pressed i'd like it to just reload the current page, i was looking to populate some fields after the process had completed for auditing purposes...But i haven't got that far yet 

incident_state = IncidentState.CLOSED;
work_notes = "Closed as Duplicate";
close_code = "Duplicate Call";
close_notes = "Closed as Duplicate";
state = IncidentState.CLOSED;

============

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>
        
        <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;
        
        alert('sysId' + sysId);
        alert('parentValue' + parentValue);
        
        var app = new GlideRecord("incident");
        if(app.get(sysId)){
            app.parent_request = parentValue;
            app.update();
        }
        window.open('/incident.do?sys_id='+sysId);
    }
}

 

Hi,

you can update the fields since you are already querying

window.open('/incident.do?sys_id='+sysId); -> this should reload the form

Is this not working?

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;

        alert('sysId' + sysId);
        alert('parentValue' + parentValue);

        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);
    }
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks @Ankur Bawiskar that has filled the values perfectly 

so what is happening with the window.open is it's opening a new tab to the same ticket but the old tab has the ui page loaded 

This is the previous tab:

find_real_file.png

This is the new window open 

find_real_file.png

Hi,

open in same window using _self

        window.open('/incident.do?sys_id='+sysId, '_self');

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader