how to populate the worknotes of change task without using current.update in the business rule

mounika32
Tera Contributor

I have written a BR on change  task table to update the worknotes when incident created . its updating the worknotes only when I use current.update(). as current.update is not  used in BR so I removed and try to give like this but the worknotes of ctask is not updating.

mounika32_0-1704259974885.png

 

How to update the worknotes ithout using current.update() in the BR?

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @mounika32 

Let's try to change your Business Rules as following

1. When to run

Before update

Conditions: Work notes changes

2. Advanced

 

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

    //insert new Incident [inc]
    var inc = new GlideRecord('incident');
	inc.initialize();
	inc.urgency = 2;
	//etc
	inc.insert();
	
	current.assigned_to = '';
	current.state = 1;
	//etc

	//set comments
    current.comments = 'Incident ' + inc.number + ' has been raised to handle this task since automation failed.';

	//remove update();

})(current, previous);

 

 

Cheers,

Tai Vu

View solution in original post

6 REPLIES 6

Anil Lande
Kilo Patron

Hi,

Can you please share when to run condition?

If it is before BR then you don't need current.update(); If it is after BR then convert it as Before BR.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

mounika32
Tera Contributor

Hi @Anil Lande 

it is after BR, when the worknotes of ctsk changes and it includes error or failed then I am creating incident and updating the worknotes with that comments.

mounika32_0-1704260748126.png

 

VaishnaviShinde
Kilo Sage

Hello @mounika32 ,

 

If you are using After BR, then try below code 

 

grStory = new GlideRecord('rm_story');// Add Your table
grStory.addQuery('sys_id', current.parent);
grStory.query();
   if (grStory.next()) {
        grStory.work_notes = '[code]<h4>Incident Number ' + inc.number;
        grStory.update();
    }

 

 

Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Vaishnavi Shinde

Tai Vu
Kilo Patron
Kilo Patron

Hi @mounika32 

Let's try to change your Business Rules as following

1. When to run

Before update

Conditions: Work notes changes

2. Advanced

 

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

    //insert new Incident [inc]
    var inc = new GlideRecord('incident');
	inc.initialize();
	inc.urgency = 2;
	//etc
	inc.insert();
	
	current.assigned_to = '';
	current.state = 1;
	//etc

	//set comments
    current.comments = 'Incident ' + inc.number + ' has been raised to handle this task since automation failed.';

	//remove update();

})(current, previous);

 

 

Cheers,

Tai Vu