- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 03:42 AM
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
and also i configured the business rule:-
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 08:40 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 12:15 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 08:40 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 11:19 AM
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)
But in BR the user email address is not pushing to custom field:-
see the code
can you please once again review the code and let me know the updates.
Thanks Regards
Chaithanya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 11:45 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 12:15 PM
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?