Updating Parent Incident with Worknotes from Incident Task - write as System and not user

TConsult
Kilo Explorer

Hi!

I want incident tasks worknotes to be updated in the parent incident worknotes.

To do this I use a business rule:

after update and Work notes changes. 

var updateIncident = current.incident.getRefRecord();
updateIncident.work_notes = current.work_notes;
updateIncident.update();

This works perfectly.

However, I also have a before query business rule (BQBR) to manage access to certain data, that checks if the user has a certain role, and if not adds something to the current query through current.addEncodedQuery. 

When this BQBR is active the incident task worknotes are not updated correctly, as the worknotes of those without the role that the BQBR requires are not updated into the parent incident. However, the notes of those that fulfill that role do appear in the parent incident. 

I thought it was the system that would copy the worknotes from the incident task and update the worknotes in incident. 

I have tried putting the Business Rule to Async, but this did not seem to work. 

My question is therefore:

Is there anyway to update the parent incident, and somehow "override" the BQBR (which needs to be there)? Is there a way to write the Incident update script in a way that the system writes to the parent incident instead of the user? 

 

 

 

2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, a quick fix may be to run your work notes update as async, and change the trigger conditions for your QBR so that it only runs for interaction sessions - && gs.getSession().isInteractive() Regards Tony

Hi Tony!

Thank you for your reply. Unfortunately I could not get this quick fix to work. 

 

Currently this is the business rule I use for getting the incident task work notes and copying them into the parent incident worknotes (after Insert/Update order 100):

	var updateIncident = current.incident.getRefRecord();
	
	
	updateIncident.work_notes = current.work_notes.getJournalEntry(1);
	
	
	updateIncident.update();

This works perfectly as long as the user has a certain role. This is because of the following before query business rule (order 100):

if (gs.hasRole('Some role,Another role') && gs.getSession().isInteractive()) 
{
		var str = '';
		current.addEncodedQuery(str);
	}
else if (gs.getSession().isInteractive()) 
	{
		var str = 'u_acl_field!=true';
		current.addEncodedQuery(str);
	}

However, the problem is that I want to be able to get the incident task work notes from users who do not have these roles. The reason is that they might have to do work on some incident task which is related to a parent incident which they do not have the permission to view. I also get the following message when the user does not have the 'Some role' org 'Another role':

Unique Key violation detected by database (Duplicate entry 'xxxxxxxxxxxxxxxxxxxxxxxx' for key 'PRIMARY')

If I make the before query business rule above not active, the incident task work notes come into the incident work notes  without any issues.

 

If you have any other suggestions please let me know!

 

Best regards,