Update Work notes and Comments between records

Robbie Lacivita
Tera Guru

Good afternoon,

I have a new table that I've built, Knowledge Tasks. This is an extension of the task table, and I have UI actions that create new knowledge tasks from incident, problem, etc.

What I would like to do now is copy work notes and comments between the records. If a comment or work note gets added to the source record, update on the knowledge task, and if a comment or work note is added to the knowledge task, update the source record.

I wrote the below After Update business rule running on the knowledge task table to update the incident record, but it does not work:

copyToIncident();

function copyToIncident() {
	var commentsChanges = current.comments.changes();
	var workNotesChanges = current.work_notes.changes();
	var watchListChanges = current.watch_list.changes();
	var workListChanges = current.work_notes_list.changes();
	
	var link = new GlideRecord("incident");
	link.addQuery("sys_id", current.u_inc_source_request);
	link.query();
	var ids = [];
	while (link.next()) {
		if (commentsChanges)
			link.comments = current.comments.getJournalEntry(1);
		if (workNotesChanges)
			link.work_notes = current.work_notes.getJournalEntry(1);
		if(watchListChanges)
			link.watch_list = current.watch_list;
		if(workListChanges)
			link.work_notes_list = current.work_notes_list;
		link.setWorkflow(false);
		link.update();
	}
}

Do you have any suggestions on how I could fix this?

Thanks!

Robbie

1 ACCEPTED SOLUTION

Robbie Lacivita
Tera Guru

I have this working now, below is the code I used:

 

updateIncident();
updateProblem();
updatePrivateTask();

function updateIncident() {
	var rec = new GlideRecord('incident');
	rec.addQuery('knowledge task',rec.u_knowledge_task);
	rec.addActiveQuery();
	rec.query();
	while (rec.next()) {
		if( rec.getDisplayValue() == current.u_inc_source_request.getDisplayValue()){
			if(current.work_notes.changes()){
				rec.work_notes = 'Work notes copied from knowledge task: '+ current.work_notes.getJournalEntry(1);
			}
			if(current.comments.changes()){
				rec.comments = 'Comments copied from knowledge task: '+ current.comments.getJournalEntry(1);
			}
			if(current.watch_list.changes()){
				rec.watch_list = current.watch_list;
			}
			if(current.work_notes_list.changes()){
				rec.work_notes_list = current.work_notes_list;
			}
			rec.update();
		}
	}
}


function updateProblem() {
	var rec = new GlideRecord('problem');
	rec.addQuery('knowledge task',rec.u_knowledge_task);
	rec.addActiveQuery();
	rec.query();
	while (rec.next()) {
		if( rec.getDisplayValue() == current.u_prob_source_request.getDisplayValue()){
			if(current.work_notes.changes()){
				rec.work_notes = 'Work notes copied from knowledge task: '+ current.work_notes.getJournalEntry(1);
			}
			if(current.comments.changes()){
				rec.comments = 'Comments copied from knowledge task: '+ current.comments.getJournalEntry(1);
			}
			if(current.watch_list.changes()){
				rec.watch_list = current.watch_list;
			}
			if(current.work_notes_list.changes()){
				rec.work_notes_list = current.work_notes_list;
			}
			rec.update();
		}
	}
}

function updatePrivateTask() {
	var rec = new GlideRecord('vtb_task');
	rec.addQuery('knowledge task',rec.u_knowledge_task);
	rec.addActiveQuery();
	rec.query();
	while (rec.next()) {
		if( rec.getDisplayValue() == current.u_private_task.getDisplayValue()){
			if(current.work_notes.changes()){
				rec.work_notes = 'Work notes copied from knowledge task: '+ current.work_notes.getJournalEntry(1);
			}
			if(current.comments.changes()){
				rec.comments = 'Comments copied from knowledge task: '+ current.comments.getJournalEntry(1);
			}
			if(current.watch_list.changes()){
				rec.watch_list = current.watch_list;
			}
			if(current.work_notes_list.changes()){
				rec.work_notes_list = current.work_notes_list;
			}
			rec.update();
		}
	}
}

View solution in original post

6 REPLIES 6

@Xavier Cordero nice input, how would you get the post button when using parent comment fields?

Robbie Lacivita
Tera Guru

I have this working now, below is the code I used:

 

updateIncident();
updateProblem();
updatePrivateTask();

function updateIncident() {
	var rec = new GlideRecord('incident');
	rec.addQuery('knowledge task',rec.u_knowledge_task);
	rec.addActiveQuery();
	rec.query();
	while (rec.next()) {
		if( rec.getDisplayValue() == current.u_inc_source_request.getDisplayValue()){
			if(current.work_notes.changes()){
				rec.work_notes = 'Work notes copied from knowledge task: '+ current.work_notes.getJournalEntry(1);
			}
			if(current.comments.changes()){
				rec.comments = 'Comments copied from knowledge task: '+ current.comments.getJournalEntry(1);
			}
			if(current.watch_list.changes()){
				rec.watch_list = current.watch_list;
			}
			if(current.work_notes_list.changes()){
				rec.work_notes_list = current.work_notes_list;
			}
			rec.update();
		}
	}
}


function updateProblem() {
	var rec = new GlideRecord('problem');
	rec.addQuery('knowledge task',rec.u_knowledge_task);
	rec.addActiveQuery();
	rec.query();
	while (rec.next()) {
		if( rec.getDisplayValue() == current.u_prob_source_request.getDisplayValue()){
			if(current.work_notes.changes()){
				rec.work_notes = 'Work notes copied from knowledge task: '+ current.work_notes.getJournalEntry(1);
			}
			if(current.comments.changes()){
				rec.comments = 'Comments copied from knowledge task: '+ current.comments.getJournalEntry(1);
			}
			if(current.watch_list.changes()){
				rec.watch_list = current.watch_list;
			}
			if(current.work_notes_list.changes()){
				rec.work_notes_list = current.work_notes_list;
			}
			rec.update();
		}
	}
}

function updatePrivateTask() {
	var rec = new GlideRecord('vtb_task');
	rec.addQuery('knowledge task',rec.u_knowledge_task);
	rec.addActiveQuery();
	rec.query();
	while (rec.next()) {
		if( rec.getDisplayValue() == current.u_private_task.getDisplayValue()){
			if(current.work_notes.changes()){
				rec.work_notes = 'Work notes copied from knowledge task: '+ current.work_notes.getJournalEntry(1);
			}
			if(current.comments.changes()){
				rec.comments = 'Comments copied from knowledge task: '+ current.comments.getJournalEntry(1);
			}
			if(current.watch_list.changes()){
				rec.watch_list = current.watch_list;
			}
			if(current.work_notes_list.changes()){
				rec.work_notes_list = current.work_notes_list;
			}
			rec.update();
		}
	}
}