Edit pop up box on close task UI Action

Russell Abbott
Kilo Sage

We have a custom pop up box when closing sc_task. It shows the 'work notes' that is required to enter in before closing the tasks.

I'd like to add 'requested_item.additonal comments' to that pop up box but to make sure we're updating the customer notes at the same time. I'm not sure where to begin. Can i add the requested_item.additional comments to the existing pop up? do i need to make another pop up that appears before or after?

 

HTML for the current pop up

<?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:evaluate var="jvar_id" expression="RP.getParameterValue('sysparm_sys_id')"/>
	<!-- <input type="hidden" value="${jvar_id}" id="kb_id"/> -->
		
	<p><b>${gs.getMessage('Please fill the work notes to proceed.')}</b></p>
	
<div class="form-horizontal no_next">
	<div class="form-group" id="work-notes-wrapper">
		<label class="col-sm-2 control-label" for="sc-work-notes">
			<span mandatory="true" class="required-marker"></span>
			${gs.getMessage('Work notes')}
		</label>
		<div class="col-sm-10">
			<textarea required="true" class="form-control sc-textarea" id="sc-work-notes" type="text" oninput="sc.workNotesOnChange()" onchange="sc.workNotesOnChange()"></textarea>
		</div>
	</div>
	</div>
	<div id="dialog_buttons" class="clearfix pull-right no_next">
		<button type="button" class="btn btn-default" onclick="sc.close()" title="${gs.getMessage('Close the dialog')}">${gs.getMessage('Cancel')}</button>
		<button type="button" class="btn btn-primary disabled" aria-disabled="true" id="sc-button" title="${gs.getMessage('Complete the Task')}" onclick="sc.taskClosure()">${gs.getMessage('OK')}</button>
</div>
</j:jelly>

Client Script for the current pop up

addLoadEvent(function() {
    (function(global) {
        var workNotes = $("sc-work-notes");
        var scBtn = $('sc-button');
        var workNotesWrapper = $('work-notes-wrapper');
        //var id = document.getElementById('kb_id').value;
        var id = g_form.getUniqueValue();

        function workNotesOnChange() {
            if (!workNotes.value.trim()) {
                workNotesWrapper.removeClassName('is-filled');
                scBtn.addClassName('disabled');
                scBtn.writeAttribute('aria-disabled', true);
            } else {
                workNotesWrapper.addClassName('is-filled');
                scBtn.removeClassName('disabled');
                scBtn.writeAttribute('aria-disabled', false);
            }
        }

        function taskClosure() {
            if (!scBtn.hasClassName('disabled')) {
                var msg = getMessage("Task is Completed");
                var notes = workNotes.value.trim();
				var timeWorked = g_form.getValue("time_worked");
				var comments = g_form.getValue("request_item.comments");
                var ga = new GlideAjax('OCH_RequestUtils');
                ga.addParam('sysparm_name', 'closeCompleteSCTask');
                ga.addParam('sysparm_id', id);
                ga.addParam('sysparm_note', notes);
				ga.addParam('sysparm_time_worked',timeWorked);
				ga.addParam('sysparm_comments',comments);
                ga.getXMLWait();
                // gsftSubmit(null, g_form.getFormElement(), 'republish_kb');
                close();
                // gsftSubmit(null, g_form.getFormElement(), 'republish_kb');
            } else {
                iframeMsgHelper.confirm({
                    msg: msg,
                    workNotes: notes,
                });
            }
        }

        function _debounce(func, wait, immediate) {
            var timeout;
            return function() {
                var context = this,
                    args = arguments;
                var later = function() {
                    timeout = null;
                    if (!immediate) func.apply(context, args);
                };
                var callNow = immediate && !timeout;
                clearTimeout(timeout);
                timeout = setTimeout(later, wait);
                if (callNow) func.apply(context, args);
            };
        }

        function close() {
            window.location.href = window.location.href + '&sysparm_next_pg=true';
        }
        global.sc = {
            taskClosure: taskClosure,
            close: close,
            workNotesOnChange: _debounce(workNotesOnChange, 200) // Only execute when left idle for 200 ms
        };

    })(window);
});
1 ACCEPTED SOLUTION

suvro
Mega Sage
Mega Sage

You can simply write a Business Rule on sc_task table

Condition

state is  CLosed COmplete AND Worknotes changes

Script

var req = new GlideRecord('sc_req_item');

req.get(current.request_item.sys_id);

req.comments = current.work_notes.getJournalEntry(-1);

req.update();

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you already have the logic in place for asking user to enter work notes

Just replicate it for comments and pass it to the Ajax as per your requirement.

regards
Ankur

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

suvro
Mega Sage
Mega Sage

You can simply write a Business Rule on sc_task table

Condition

state is  CLosed COmplete AND Worknotes changes

Script

var req = new GlideRecord('sc_req_item');

req.get(current.request_item.sys_id);

req.comments = current.work_notes.getJournalEntry(-1);

req.update();

This worked for me, copying that note means that each SC_TASK still has it's own note, and the RITM gets a copy of each SC_TASKS notes.

Just a heads up for anyone else that might happen across this post.

-1 will get you all the notes

1 will get you the final note only

Thanks