Copy all worknotes from incident on the worksspace

Chandler2
Tera Guru

Hi All,

 

I want to copy all worknotes from Interaction to Incident when user clicks Create incident on the worksspace view.

 

Now, there are multiple Create Incident on Interaction table but I am taking the one which has "Workspace Form Button" as true.

 

There is a line of code:

inc.work_notes = gs.getMessage('Incident created from Interaction {0}', current.number); // This seems to be working fine
 
Now I added below line so I can copy all the worknotes but it doesn't work
I would like to append it to the above entry itself but it is not doing anything at all.
 
inc.work_notes = current.getJournalEntry(-1);  //What is the issue here?
 
I also tried     inc.work_notes = current.interaction.getJournalEntry(-1);  // This one also doesn't work
 
Please suggest the reason.

 

1 ACCEPTED SOLUTION

Chaitanya ILCR
Mega Patron

Hi @Chandler2 ,

I have updated the Create Incident UI action and tested it's working for me try this out

inc.work_notes = current.work_notes.getJournalEntry(-1)

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

10 REPLIES 10

Hi @Chandler2 

that should work 

which UI action are you updating ? the one that's on the interaction table only right?

ChaitanyaILCR_0-1743095434814.png

as an alternative you can try a BR

 

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

	// Add your code here
	var incintGr = new GlideRecord('interaction_related_record');
	incintGr.addEncodedQuery('type=task^document_table=incident^task='+current.sys_id);
	incintGr.query();
	if(incintGr.next()){
		current.work_notes = incintGr.interaction.work_notes.getJournalEntry(-1);
	}

})(current, previous);

 

you can create a before insert br on incident table with above script as well

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Yeah, very weird. It works in my PDI but not on the other instance.

I see multiple Create incident on interaction table but I have choosen the one which has workspace form view as true and that is only one.

 

Any ideas, what could be happening?

How to know if it is UI action and not a declarative action?

@Chandler2 

 

I think this is the sysid of that UI action a89d504b873303002ae97e2526cb0bdd

should be same in your instance to if not you can check by inspecting the element and copy component name and remove _node1_ the remaining last 32 characters is the sys id of the ui action usually

ChaitanyaILCR_0-1743097572474.png

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

That is correct, same sys id I have too and below is how the code is placed:

if (gs.getProperty("com.snc.incident.create_from_interaction.save") === 'true') {
inc.work_notes = gs.getMessage('Incident created from Interaction {0}', current.number);
inc.work_notes = current.work_notes.getJournalEntry(-1);

Ankur Bawiskar
Tera Patron
Tera Patron

@Chandler2 

your syntax is wrong.

Use the syntax shared by other members.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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