How to get display value from assigned_to for Business Rule

Gioo
Tera Expert

Hi everyone,

 

I am trying to create an email notification using business rule and event registry where an email is generated with details of an asset. However, my following structure uses .getDisplayValue for assigned_to field and that returns an ID instead of the user name.

 

Could anyone advise me on the following steps to achieve the expected result?

 

My workflow is based on the following:

 

Event Registry

 

Event name asset.assign.notification

Table alm_hardware

Fired by Business Rule: Asset Assign Changes

 

Business rule

 

 

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

	//If the asset assigned to changes, queue the event
	if(current.assigned_to.changes()){

		//Get previous value
		var value = previous.assigned_to.getDisplayValue();

		//Get current value
		var newValue = current.assigned_to.getDisplayValue();

		gs.eventQueue("asset.assign.notification", current, value, newValue);
	}

})(current, previous);

 

 

Notification

 

Table alm_hardware

Type EMAIL

Active true

 

When to send:

Send when Event is fired

Event name asset.assign.notification

 

Who will receive:

Users System Administrator

 

What it will contain:

Subject The asset assigned to has changed

Message HTML

 

 

The following asset: ${asset_tag} assigned to has changed from:${event.parm1}  to: ${event.parm2} and that has been changed by: ${sys_updated_by}.

Regards,
IT

 

 

Preview Notification

 

 

The following asset: P1000479 assigned to has changed from:6816f79cc0a8016401c5a33be04be441  to: and that has been changed by: admin.

Regards,
IT

 

 

Thank you in advance for you time.

Regards,

Gio

 

1 ACCEPTED SOLUTION

Sohail Khilji
Kilo Patron
Kilo Patron

Use the below code it must help , bcoz the emaill body accepts HTML/TEXT. Replace to the below 2 lines in your code.

 

var value = previous.assigned_to.name.toString();
var newValue = current.assigned_to.name.toString();

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

View solution in original post

4 REPLIES 4

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Looking at you output seems that the user table does not have a display value so it is returning the sysid. 

 

Please use the below code and change your BR to before update if not done already.

Saurav11_0-1703068117350.png

 

 

 

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

	//If the asset assigned to changes, queue the event
	if(current.assigned_to.changes()){

		//Get previous value
		var value = previous.assigned_to.name;

		//Get current value
		var newValue = current.assigned_to.name;

		gs.eventQueue("asset.assign.notification", current, value, newValue);
	}

})(current, previous);

 

 

Please mark my answer as correct based on impact,

Sohail Khilji
Kilo Patron
Kilo Patron

Use the below code it must help , bcoz the emaill body accepts HTML/TEXT. Replace to the below 2 lines in your code.

 

var value = previous.assigned_to.name.toString();
var newValue = current.assigned_to.name.toString();

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hi @Sohail Khilji,

 

That has actually worked and such a simple fix.

 

Thank you so much for the help.

 

Regards,

Gio