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

I'm using before BR with update functionality and it's finally pushing the email value into custom filed

use below code for expected output

Chaitanya6_0-1665682920704.png

 

Thanks to everyone and I really appreciating guys,

Chaithanya.

 

 

Adrian Ubeda
Mega Sage

Hi Chaithanya,

I've read the first post that Brad wrote, and I've added some lines in your business rule. Use a Business rule on after and use this lines:

var x = new getusermail();
var mail = x.mail(current.assigned_to.toString());
current.setValue('u_emailofassignedto2', email);
current.update();


If it was helpful, please give positive feedback.
Thanks,



If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆