- 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-13-2022 10:37 AM
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
Thanks to everyone and I really appreciating guys,
Chaithanya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 12:00 PM
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,
☆ Community Rising Star 22, 23 & 24 ☆