The CreatorCon Call for Content is officially open! Get started here.

Calling script include from business rule

Chaitanya6
Tera Contributor

Hi Community,

 

I want to push the assigned to email address in current problem form by using business rule and script include combination:-

 

i configured below script include for fetching the assigned to email address

Chaitanya6_0-1665571388083.png

and also i configured the business rule:-

 

Chaitanya6_1-1665571505238.png

 

Here i need to set the return value to one custom field.

can any one help in my code? and i really appreciate you guys

 

Thanks,

Chaithanya.

 

2 ACCEPTED SOLUTIONS

Brad Bowman
Kilo Patron
Kilo Patron

Try a Business Rule script more like this:

(function executeRule(current, previous /*null when async*/) {
	var x = new getusermail();
	current.field_name = x.mail(current.assigned_to);
})(current, previous);

where field_name is the name of the custom field you want to set the value of, and assigned_to is the name of the field on the current record that is a reference to sys_user.  If you are running this Business Rule after insert/update, add a current.update(); line.  In your Script Include remove the var usr line as that is used when called from a client script.  Change the function line to 

mail: function(usr) {

to use the assigned to passed in from the BR.  Also, the email field on the user table can be tricky, so force it to a string to avoid unexpected results

var email = gr.email.toString();

I should also mention that you can do all of this without a Script Include since the user field is a reference

(function executeRule(current, previous /*null when async*/) {
	current.field_name = current.assigned_to.email.toString();
})(current, previous);

View solution in original post

Run the Business Rule before Update, or as others have so helpfully offered, add current.update(); if you are running this after Update.  Also, what is the field type of u_emailofassignedto2?

View solution in original post

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

Try a Business Rule script more like this:

(function executeRule(current, previous /*null when async*/) {
	var x = new getusermail();
	current.field_name = x.mail(current.assigned_to);
})(current, previous);

where field_name is the name of the custom field you want to set the value of, and assigned_to is the name of the field on the current record that is a reference to sys_user.  If you are running this Business Rule after insert/update, add a current.update(); line.  In your Script Include remove the var usr line as that is used when called from a client script.  Change the function line to 

mail: function(usr) {

to use the assigned to passed in from the BR.  Also, the email field on the user table can be tricky, so force it to a string to avoid unexpected results

var email = gr.email.toString();

I should also mention that you can do all of this without a Script Include since the user field is a reference

(function executeRule(current, previous /*null when async*/) {
	current.field_name = current.assigned_to.email.toString();
})(current, previous);

Hi Brad, thanks for response!

 

yes, I also know that we can do all of this without script include here just  i am trying the possibility to call the script include from business rule.

 

I tried your modifications in script include and it's working fine(it's returning email address)

Chaithanya_1-1665598633537.png

 

 

 

 

But in BR the user email address is not pushing to custom field:-

see the code

Chaithanya_0-1665598545883.png

can you please once again review the code and let me know the updates.

 

Thanks Regards

Chaithanya.

 

Hello,

 

What is the when to run condition on your BR? is it after insert/update? If yes please add the below line to the code:-

 

current.update();

 

Please mark answer correct/helpful based on Impact.

Run the Business Rule before Update, or as others have so helpfully offered, add current.update(); if you are running this after Update.  Also, what is the field type of u_emailofassignedto2?