Trigger Metric Definition from Business Rule

Ricky S Larsson
Tera Guru

I have a Metric Definition that creates a Metric when the Additional Comments field is changed: An agent writes a comment and a metric check the time from when the ticket is created until someone wrote a comment.

Now I also need to trigger this Definition when someone writes a Close Note. I need to trigger the same definition, so I can't create a new Definition. Problem is, only one field can be tracked in a Metric Definition.

The beginning of the Metric Definition script looks like this:

if (new SFGAdditionalComments().isAssignmentGroupMember(current.sys_id, current.assignment_group)) {
	createMetric();
}

function createMetric()

// The rest of the code is the function

My idea is to create a Business Rule that would trigger this Definition, or specifically trigger the createMetric() function (To bypass the If statement)

How would I write my Business Rule to do just that?

1 ACCEPTED SOLUTION

I wrote it exactly like you wrote. The last parameter just went down one line in my post so it seemed like it was missing.

But I found the solution to this problem: The field needs to be inside of [ ] brackets

The problem was that I wrote 'comments' instead of '[comments]'

This line of code works:

gs.eventQueue('metric.update', current, '[comments]', current.sys_mod_count, 'metric_update');

 

Thank you for pointing me in the right direction!

View solution in original post

6 REPLIES 6

VigneshMC
Mega Sage

Write an BR to trigger below event whenever Close Note is updated, in place of fields pass additional comments field name, so that additional comments metric gets updated.

gs.eventQueue('metric.update', current, fields, current.sys_mod_count, 'metric_update');

I can't get it to start the event, or it just won't trigger the metric. The business rule starts because I can see the test gs.log in the logs.

This is what I wrote:

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

	// Add your code here
	gs.log('HR METRIC: Does this BR start?');
	gs.eventQueue('metric.update', current, 'comments', current.sys_mod_count, 'metric_update');	

})(current, previous);

 

 

You missed to add a parameter while triggering events, below is the syntax

 

gs.eventQueue('metric.update', current, fields, current.sys_mod_count, 'metric_update');

I wrote it exactly like you wrote. The last parameter just went down one line in my post so it seemed like it was missing.

But I found the solution to this problem: The field needs to be inside of [ ] brackets

The problem was that I wrote 'comments' instead of '[comments]'

This line of code works:

gs.eventQueue('metric.update', current, '[comments]', current.sys_mod_count, 'metric_update');

 

Thank you for pointing me in the right direction!