Additional comments to catalog task tickets are not shown in the user portal interface.

Shiri
Kilo Contributor

The additional comments that the fulfillers enters to catalog task tickets (REQs) are not shown in the user portal interface.

However the additional comments that are entered to Incident tickets (INC) are shown in the user portal interface.

We do have notification set up - so the user will get an email about the additional comment, but we want it to be shown in the user portal interface as well.

 

9 REPLIES 9

Hello Brian,

first i used both of your BR above. But transfer User comments from Portal to task did not work.

I found another BR, which almost works for me..

(function executeRule(current, previous /*null when async*/) {

updateTasks();

function updateTasks() {

var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', current.sys_id);

sctask.addActiveQuery();

sctask.query();
while (sctask.next()) {
sctask.work_notes = 'Additonal Comment from RITM' + current.comments;
sctask.update();
}
}
})(current, previous);

 

Only problem now is:

User write a comment at Portal. The comment is now also shown at sc_task (worknotes) but is only visible for the admin. user with itil role can not see this worknotes. I guess i need ACL

Ok, i changed 

sctask.work_notes = 'Additonal Comment from RITM' + current.comments;

to

sctask.comments = 'Additonal Comment from RITM' + current.comments;

and now the user comment from portal is visible in sc_task.

BUT now, i got a small loop, when the technical post an additional comment (on sc_task) its visible in portal, but its visible twice at the task.

On the request item BR you need to put in a check to see if the updated by which is user ID is the requested_for or Opened_by (if you allow them to see it) to make sure you don't get a loop.  This section of the code in my original BR above.  I'm only checking requested_for since we did not allow opening RITMs on behalf of someone else.

var user = new GlideRecord ('sys_user');
		user.addQuery('user_name', current.sys_updated_by);
		user.query();
		if (user.next()){
			if (user.sys_id == current.request.requested_for)

Brian Lancaster
Tera Sage

I have made modifications to my business rule to make the code less complicated. I am also passing back and for work notes. So there is a total of 4 business rules. One for work notes and one for comments on both the sc_req_item and sc_task table. They are all before update business rules with a condition of Work Notes changes or Comments changes. Here is the much simper coding.

These first two are on the sc_req_item table.

Condition: comments changes

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    if (!(current.comments.toString().toLowerCase().indexOf('comments from task:') > -1)) {
        var str = "Comments from RITM: \n";
		var gr = new GlideRecord ('sc_task');
		gr.addQuery('request_item', current.getValue('sys_id'));
		gr.addQuery('active', true);
		gr.query();
		while (gr.next()){
			gr.comments = str + current.comments.getJournalEntry(1);
			gr.update();
		}
    }

})(current, previous);

Condition Work Notes changes

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    if (!(current.work_notes.toString().toLowerCase().indexOf('work notes from task:') > -1)) {
        var str = "Work Notes from RITM: \n";
		var gr = new GlideRecord ('sc_task');
		gr.addQuery('request_item', current.getValue('sys_id'));
		gr.addQuery('active', true);
		gr.query();
		while (gr.next()){
			gr.work_notes = str + current.work_notes.getJournalEntry(1);
			gr.update();
		}
    }

})(current, previous);

These ones are on the sc_task table.

condition comments changes 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    if (!(current.comments.toString().toLowerCase().indexOf('comments from ritm:') > -1)) {
        var str = "Comments from TASK: \n";
        var gr = new GlideRecord('sc_req_item');
        gr.addQuery('sys_id', current.getValue('request_item'));
        gr.addQuery('active', true);
        gr.query();
        if (gr.next()) {
            gr.comments = str + current.comments.getJournalEntry(1);
            gr.update();
        }
    }

})(current, previous);

condition work notes changes

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    if (!(current.work_notes.toString().toLowerCase().indexOf('work notes from ritm') > -1)) {
        var str = "Work notes from TASK: \n";
        var gr = new GlideRecord('sc_req_item');
        gr.addQuery('sys_id', current.getValue('request_item'));
        gr.addQuery('active', true);
        gr.query();
        if (gr.next()) {
            gr.work_notes = str + current.work_notes.getJournalEntry(1);
            gr.update();
        }
    }

})(current, previous);

 

verda
Mega Expert

I know this is a pretty late response but if you wish to add some comments to the ticket form programmatically from your workflow you need to add the following to your script:

Your script runs on sc_req_item and the comments are on sc_request. The field that references this record is "request" on sc_req_item.

var gr = new GlideRecord('sc_request');
gr.get(current.request);
gr.comments='My programmatic comment'
gr.update();

find_real_file.png