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
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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks @Ankur Bawiskar 

This looks great i've tested using 

alert(shortDesc);

and confirmed the value is correct, however i've amended this to description instead of short description

i need to try and pass this value to the parent ticket as a work note now however, i can't us app.work_notes because this would up the closed ticket instead of the parent...

Am i able to leverage the parent ticket info to update with that description value? 

Thank you 

Hi,

yes you will have to override OR append it

It depends on your case

app.work_notes = gel('incidentShortDescription').value + "Closed as Duplicate";

regards
Ankur

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

Thanks @Ankur Bawiskar 

I'm trying to take the description from the ticket closed and add is as a work note to the ticket just added as the parent as most of the time the duplicate is part of an email chain... i've been asked to put missing part back into the original ticket if that makes sense 

cheers