i have a br which updates comments from ritm to incident and vice -versa.

Debasis Pati
Tera Guru

Hi,

i have a br which copies the additional comments from ritm to incident.

i have a another br which copies additional comment from incident to ritm.

now the issue is because there are two business rules if i strt commenting ritm it copies to incident but the 2nd business rule again copies the same to incident.Now how to restrict i need both the br because the requirement is 2 way.

@Ankur Bawiskar any suggestions???

Regards,

Debasis

 

1 ACCEPTED SOLUTION

Hi,

update as this

br on incident table--after -update

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.u_request_item);
ritm.query();
if (ritm.next() ) {
	var curWN = current.work_notes.getJournalEntry(1);
	if(ritm.work_notes.getJournalEntry(1) == '' || curWN.indexOf(ritm.work_notes.getJournalEntry(1)) <0){
		ritm.comments = current.comments.getJournalEntry(1).match(/\n.*/gm).join("\n");
		ritm.update();
	}
}

br on ritm table

var inc = new GlideRecord('incident');
inc.addQuery('u_request_item', current.sys_id);
inc.query();
if (inc.next() ) {
	gs.addInfoMessage("inside from ritm");
	var curWN = current.work_notes.getJournalEntry(1);
	if(inc.work_notes.getJournalEntry(1) == '' || curWN.indexOf(inc.work_notes.getJournalEntry(1)) <0){
		inc.comments = current.comments.getJournalEntry(1).match(/\n.*/gm).join("\n");
		inc.update();
	}
}

Regards
Ankur

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

View solution in original post

18 REPLIES 18

var ritm=new GlideRecord('sc_req_item');
 ritm.addQuery('sys_id',current.u_request_item);
 ritm.query();
if(ritm.next())
 {
 ritm.comments=current.comments;
 ritm.work_notes=current.work_notes;
ritm.update();

 }
 ritm.update();

 

The above is the sample code.

Change both BR to after and then use below sample code. 

var ritm=new GlideRecord('sc_req_item');
 ritm.addQuery('sys_id',current.u_request_item);
 ritm.query();
if(ritm.next())
 {
 ritm.comments=current.comments;
 ritm.work_notes=current.work_notes;
 ritm.setWorkflow(false);
 ritm.update();
 }

Let me know if you still face any issue.

br on ritm table


var inc = new GlideRecord('incident');
inc.addQuery('u_request_item', current.sys_id);
inc.query();
if (inc.next()) {

inc.work_notes = current.work_notes;
inc.comments = current.comments;
 inc.setWorkflow(false);
inc.update();

}

br on inc table

 

var ritm=new GlideRecord('sc_req_item');
ritm.addQuery('sys_id',current.u_request_item);
ritm.query();
if(ritm.next())
{
ritm.comments=current.comments;
ritm.work_notes=current.work_notes;
ritm.setWorkflow(false);
ritm.update();
}

if i use setworkflow false it doesnt copy only without that also with after br it didnt copied the comments .

 

Please once have alook

i tried the below logic as well to restrict

 

var count = 0;
 var secondLastComment = '';

 var jor = new GlideRecord('sys_journal_field');
 jor.addQuery('element_id', current.sys_id);
 jor.addQuery('name', 'incident');
 jor.addQuery('element', 'comments');
 jor.orderByDesc('sys_created_on');
 jor.setLimit(1);
 jor.query();

 while (jor.next()) {

 secondLastComment = jor.getValue('value');
 gs.addInfoMessage(secondLastComment);
 }

Change your both BRs to after then 

BR for RITM

    var inc = new GlideRecord('incident');
    inc.addQuery('u_request_item', current.sys_id);
    inc.query();
    if (inc.next()  && current.comments) {
        inc.comments = current.comments.getJournalEntry(1).match(/\n.*/gm).join("\n");
        inc.update();
    }

 

BR for incident:

  var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('sys_id', current.u_request_item);
    ritm.query();
    if (ritm.next() && current.comments) {
			ritm.comments = current.comments.getJournalEntry(1).match(/\n.*/gm).join("\n");
        ritm.update();
    }

 

Hope it helps

Upender Kumar
Mega Sage

use gs.session().isInteractive() in the BR condition