We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Copy Description to worknote using ui action?

Sam Motley
Giga Guru

Hi all, 

I have a UI action that calls a ui page this prompts a user to input a parent ticket which then closes that ticket with the parent copied to the field. 

This works great thanks to @Ankur Bawiskar however i've been asked if we can take the description from the ticket closed and add it as a work note on the parent ticket. 

====

UI action code: 

function commentsDialog() {
    var gm = new GlideModal('Add Parent Reference');
    gm.setTitle('Show title');
    gm.setPreference('sys_id', g_form.getUniqueValue());
    gm.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>
        
        <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');
    alert('current.description');
    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.u_request_close_code = "Duplicate Call";
            app.state = '7';
            app.update();
            GlideDialogWindow.get().destroy();
        }
        window.open('/incident.do?sys_id='+sysId, '_self');
    }
}

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

Hi,

you can send the description from UI action to UI page and update

function commentsDialog() {
    var gm = new GlideModal('Add Parent Reference');
    gm.setTitle('Show title');
    gm.setPreference('sys_id', g_form.getUniqueValue());
    gm.setPreference('short_description', g_form.getValue('short_description'));
    gm.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>

        <g:evaluate var="jvar_sysid" expression="RP.getWindowProperties().get('sys_id')"/>
        <g:evaluate var="jvar_shortDescription" expression="RP.getWindowProperties().get('short_description')"/>
        
        <input type="hidden" id="cancelled" name="cancelled" value="false"/>
        <input type="hidden" id="incidentSysID" name="incidentSysID" value="${jvar_sysid}"/>
        <input type="hidden" id="incidentShortDescription" name="incidentShortDescription" value="${jvar_shortDescription}"/>
        
        <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');
    alert('current.description');
    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";
            
            var shortDesc = gel('incidentShortDescription').value;
            // now use it            
            
            app.close_code = "Duplicate Call";
            app.close_notes = "Closed as Duplicate";
            app.u_request_close_code = "Duplicate Call";
            app.state = '7';
            app.update();
            GlideDialogWindow.get().destroy();
        }
        window.open('/incident.do?sys_id='+sysId, '_self');
    }
}

regards
Ankur

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

View solution in original post

5 REPLIES 5

Hi,

you need to discuss with customer whether they want work notes to be appended with short description or not

Regards
Ankur

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