How to send a Mail on update particular Field

Posted by mysteryminds on 17-Nov-2014 13:45

Dear RB Gurus

I have a query related to sending a mail 

Can someone explain to me steps to do to send a mail on field update. 

I have to create any specific field  (e.g: group of Option boxes / Text Fields / Currency Fields ) or any other fields>
if the field is updated in a view / Page / tab 

It has to shoot a mail to me saying XYZ field was "THIS" and it has been udpated to "THAT " now 

The field can be updated in multiple location (e.g thru mass update / Workflow / human intervention  / mobile) but the mail has to shoot once the field has BEEN MODIFIED /UPDADTED only

All Replies

Posted by Gian Torralba on 17-Nov-2014 14:53

Hello,

Please see a similar post on how to send an email on an update of a particular field.https://community.progress.com/community_groups/rollbase/f/25/t/13395.aspx


Thank you,
Gian

Posted by mysteryminds on 17-Nov-2014 15:03

i'm afraid the page link you provided seems to be down

"Sorry, there was a problem with your last request!

Either the site is offline or an unhandled error occurred. We apologize and have logged the error. Please try your request again or if you know who your site administrator is let them know too.'

Posted by Gian Torralba on 17-Nov-2014 15:10

Hello,

Please try this link instead: https://community.progress.com/.../13395.aspx

Thank you,

Gian

Posted by mysteryminds on 17-Nov-2014 15:43

Hi Gian

Thanks for the info... But that seems to be confusing me, as I'm novice to RB and really don't have that expertise knowhow like yours, but my mind works very logically.

Give me a single field update option, the way its published there seems to be very confusing to me.

Whats needs to be done first

Whats needs to be done Second

What needs to be done third

What needs to be done Fourth and if its final

So that I can create my own document and keep it.

I don't  mind shortcuts but it has to be sequential so that I don't bother everyone in the community time and again please

I guess I'm not being too demanding..... Just trying to learn the right way

Posted by Gian Torralba on 17-Nov-2014 16:18

Hello,

I'll explain it clearly here:

1. First, create a duplicate of the field you need to compare with. If it is a text field, create a new text field. This will hold the previous value of the original text field. (text field 1 is the original field and text field 2 is the cloned field)

2. Create an "After Update" trigger that sets the value on the cloned text field.

3. Create a "Send Email" trigger that will send the email conditionally. This checks if the field value is changed.

4.  The trigger hierarchy should be like this:

- 1. Send Email

- 2. Update Previous Value

5. For the email template, create a formula field that will hold the dynamic value to be displayed in the email. Add the formula field token in the email template afterwards.

Hope this is clear enough. Let me know if you have any more questions.

Thank you,

Gian

return "{!text_field_1#value}";

Posted by Gian Torralba on 17-Nov-2014 16:26

Hello,

I'll explain it clearly here:

1. First, create a duplicate of the field you need to compare with. If it is a text field, create a new text field. This will hold the previous value of the original text field. (text field 1 is the original field and text field 2 is the cloned field)



2. Create an "After Update" trigger that sets the value on the cloned text field.



3. Create a "Send Email" after update trigger that will send the email conditionally. This checks if the field value is changed.



4.  The trigger hierarchy should be like this:

- 1. Send Email

- 2. Update Previous Value

5. For the email template, create a formula field that will hold the dynamic value to be displayed in the email. Add the formula field token in the email template afterwards.



Hope this is clear enough. Let me know if you have any more questions.

Thank you,

Gian

Posted by mysteryminds on 17-Nov-2014 17:13

I wasn't able to create different fields in my system due to the fact we crossed list of fields available in the object.

So this is the way I'm trying to do things and make it work... But unfortunately its not anywhere close to what I'm thinking it is....

Let me explain to you what I've been doing so far

MAIL CONTENT  field value

if("{!R52185052.xyz#value}"=="Locked" ||"{!R52185052.xyz#value}"=="Expired" ||"{!R52185052.xyz#value}"=="Cancelled")

{

var content = "";

var fi="{!abc}";

var bfi="{!R77816268.before_abc}";

if(fi != bfi){

content += "abc  <br></br>";}

var cfi="{!aaa}";

var bcfi="{!R77816268.before_aaa}";

if(cfi != bcfi){

content += "aaa  <br></br>";}

var sp="{!bbb#id}";

var bsp="{!R77816268.before_bbb#value}";

if(sp != bsp ){

content += "bbb  <br></br>";}

return content;

}

-------------------------------------

TRIGGER  - Lock Desk Changes SP

if("{!R52185052.xyz#value}"=="Locked" ||"{!R52185052.xyz#value}"=="Expired" ||"{!R52185052.xyz#value}"=="Cancelled")

{

if ("{!abc}" != "{!R77816268.before_abc}" ||"{!co_borrower_aaa}" != "{!R77816268.before_co_borrower_aaa}")

{

return true;

}

else {return false;}

}

----------------------------------

Trigger Name - update to Client2 New

if("{!R52185052.xyz#value}"=="Locked" ||"{!R52185052.xyz#value}"=="Expired" ||"{!R52185052.xyz#value}"=="Cancelled")

{

var fi= rbv_api.getFieldValue("client6",{!id}, "abc");

rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_abc", fi);

var cfi= rbv_api.getFieldValue("client6",{!id}, "co_borrower_aaa");

rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_co_borrower_aaa", cfi);

}

-----------------------------------------------

----------------------------------

EMAIL TEMPLATE - Lock Desk Changes SP

Attention Lock Desk,

Client : {!name#text}

info # : {!lnumber#value}

The following fields have changed in this record:

{!mail_content_new#value}

After all this doing... When I change a field in the system I still do not see which field has been changed or modified.

Where am I going wrong

Posted by Gian Torralba on 18-Nov-2014 08:47

Hello,

I've cleaned some of the code since you are comparing the ID with the [tag:value] which will not work. Can you check if the records being tested have a related record and also please use the debug mode in triggers to check if it is entering the conditions you specified and if there are no errors on the triggers.

-------------------------------------

formula field to be displayed in the email

if("{!R52185052.xyz#value}"=="Locked" || "{!R52185052.xyz#value}"=="Expired" || "{!R52185052.xyz#value}"=="Cancelled")
{
    var content = "";
    var fi="{!abc#value}";
    var bfi="{!R77816268.before_abc#value}";

    if(fi != bfi){
        content += "abc<br></br>";
    }
        
    var cfi="{!aaa#value}";
    var bcfi="{!R77816268.before_aaa#value}";
        
    if(cfi != bcfi){
        content += "aaa<br></br>";
    }
            
    var sp="{!bbb#value}";
    var bsp="{!R77816268.before_bbb#value}";

    if(sp != bsp ){
        content += "bbb<br></br>";
    }

    return content;
}

-------------------------------------

TRIGGER  - Lock Desk Changes SP

if("{!R52185052.xyz#value}"=="Locked" ||"{!R52185052.xyz#value}"=="Expired" ||"{!R52185052.xyz#value}"=="Cancelled")
{
    if ("{!abc#value}" != "{!R77816268.before_abc#value}" || "{!co_borrower_aaa#value}" != "{!R77816268.before_co_borrower_aaa#value}")
    {
        return true;
    }
    else
    {
        return false;
    }
}

-------------------------------------

Trigger Name - update to Client2 New

if("{!R52185052.xyz#value}"=="Locked" ||"{!R52185052.xyz#value}"=="Expired" ||"{!R52185052.xyz#value}"=="Cancelled")
{
    var fi= "{!abc#value}";
    rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_abc", fi);

    var cfi= "{!co_borrower_aaa#value}";
    rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_co_borrower_aaa", cfi);
}

TRIGGER HIERARCHY
1. Lock Desk Changes SP | after update trigger
2. update to Client2 New | after update trigger

Hope this helps.

Thank you,

Gian

Posted by mysteryminds on 19-Nov-2014 13:46

Hello Gian

I'm not able to send the values by mail  

which means "I'm not getting values of my PREVIOUS VALUE and CHANGED TO VALUE"

my mailcontent formula field has this

Field Type : FORMULA (string)

if("{!R52185052.lock_status#value}"=="Locked" ||"{!R52185052.lock_status#value}"=="Expired" ||"{!R52185052.lock_status#value}"=="Cancelled")

{

var sp="{!special_program#value}";

var bsp="{!R77816268.before_special_program#value}";

if(sp != bsp ){

content += "Special Program values changed from " +sp+ to +bsp;}

return content;

}

Posted by Gian Torralba on 19-Nov-2014 14:17

Hello,

Can you use the debug feature in trigger #2 just to see if it is updating the previous field value properly? Make sure you are using the correct relationship name.

-------------------------------------

Trigger Name - update to Client2 New

if("{!R52185052.xyz#value}"=="Locked" ||"{!R52185052.xyz#value}"=="Expired" ||"{!R52185052.xyz#value}"=="Cancelled")
{
    var fi= "{!abc#value}";
    rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_abc", fi);

    var cfi= "{!co_borrower_aaa#value}";
    rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_co_borrower_aaa", cfi);
}


Thank you,

Gian

Posted by mysteryminds on 19-Nov-2014 14:49

Gian

My main issue in here is that its not picking the values as it shows while I debug.

I'm just presuming that the way I'm writing the code is wrong

if("{!R52185052.lock_status#value}"=="Locked" ||"{!R52185052.lock_status#value}"=="Expired" ||"{!R52185052.lock_status#value}"=="Cancelled")

{

var content = "";

var fi="{!ficouw}";

var bfi="{!R77816268.before_abc}";

if(fi != bfi){

content += "aaabbbbbccccc  <br></br>";}

var cfi="{!co_borrower_ficouw}";

var bcfi="{!R77816268.before_co_borrower_aaa}";

if(cfi != bcfi){

content += "aaaaaaaaaaaaaaaaaa <br></br>";}

var sp="{!special_program#id}";

var bsp="{!R77816268.before_special_program#value}";

if(sp != bsp ){

content += "Special Program <br><br>";}

return content;

}

OUTPUT by MAIL i get

Attention <bla bla bla>,

Client : clientname

LOAN # : 1411120000

The following fields have changed in this record:

Special Program

Thank you,

company

but I would expect is to have

SPECIAL PROGRAM  value has changed

Previous Value =  ONE

Current Value = TWO

so I need to show the values "SP" and "BSP"

I suppose this is clear...

Posted by Gian Torralba on 19-Nov-2014 14:59

Hello,

Is the formula field the only problem that you are encountering? If so, I edited the script and added the tokens to be displayed in the formula field:

if("{!R52185052.lock_status#value}"=="Locked" ||"{!R52185052.lock_status#value}"=="Expired" ||"{!R52185052.lock_status#value}"=="Cancelled")
{
    var content = "";
    var fi="{!ficouw}";
    var bfi="{!R77816268.before_abc}";

    if(fi != bfi){
        content += "aaabbbbbccccc  <br></br>";
    }


    var cfi="{!co_borrower_ficouw}";
    var bcfi="{!R77816268.before_co_borrower_aaa}";

    if(cfi != bcfi){
        content += "aaaaaaaaaaaaaaaaaa <br></br>";
    }

    var sp="{!special_program#id}";
    var bsp="{!R77816268.before_special_program#value}";

    if(sp != bsp ){
        content += "Special Program <br><br>";
        content += "Previous Value = "+bsp+"<br>";
        content += "Current Value = "+sp+"<br>";
    }

    return content;
}

Posted by mysteryminds on 19-Nov-2014 15:58

Thanks Gian

Now I see some things happening and receiving some data which might be helpful.

The current challenge is that I'm not getting the Values of the Variables 

E.g special program  field :  which is a group check box 

for now special program has around 20 group radio boxes so if i select one radio box 
e.g : special program : HOUSE  
in th email it must display special program : current Value : house 

But right now its showing something like : ID values in numeric


Client : tester,test
The following fields have changed in this record:

FICO (UW INPUT) 
Co-Borrower FICO(UW INPUT) 
Special Program 

Previous Value = 98558090 [ in place of this I would like to see it as  BUNGALOW]
Current Value = 62382552 [HOUSE]

also I'm facing some small challenge which is  "receiving mails even though above 3 mentioned fields are not changed " the trigger is invoking mails 
Is there a way to tell the system to send the mail unless and untill only these 3 fields are changed or amended.....

Posted by Gian Torralba on 19-Nov-2014 16:08

Hello,

If both fields are group of radio button, just use the #value instead. Please refer to the Rollbase User Guide, Chapter 5: Adding Business Logic for more information on how to use each token types.

var sp="{!special_program#value}";
var bsp="{!R77816268.before_special_program#value}";

You need to check the token types if they are correct so that the email trigger will fire properly. Please use the debug function to check the conditions if correct.

Hope this helps,

Gian


    var sp="{!special_program#id}";
    var bsp="{!R77816268.before_special_program#value}"; - See more at: https://community.progress.com/community_groups/rollbase/f/25/p/14348/51714.aspx#51714
Posted by mysteryminds on 19-Nov-2014 17:47

Hi Gian

I tried the token and still there is only issue with one field which is previous value. Even though I'm referrring to it as value.

Special Program

Previous Value = 105671647

Current Value = VA SL

var sp="{!special_program#value}";

var bsp="{!R77816268.before_special_program#value}";

       content += "Previous Value = "+bsp+"<br>";

       content += "Current Value = "+sp+"<br>";

@Gian do you think there is a error in this BEFORE UPDATE TRIGGER

update to Client2 New

if("{!R52185052.lock_status#value}"=="Locked" || "{!R52185052.lock_status#value}"=="Expired"||"{!R52185052.lock_status#value}"=="Cancelled")

{

var fi= rbv_api.getFieldValue("client6",{!id}, "ficouw");

rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_fico", fi);

var cfi= rbv_api.getFieldValue("client6",{!id}, "co_borrower_ficouw");

rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_co_borrower_fico", cfi);

var sp= rbv_api.getFieldValue("client6",{!id}, "special_program");

rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_special_program", sp);

}

Posted by Gian Torralba on 20-Nov-2014 14:31

Hello,

Can you modify the highlighted line with this? I just tested this and it returns both values rather than IDs

var sp= rbv_api.getFieldValue("client6",{!id}, "special_program");

var sp= rbv_api.getValueById("client6", "special_program", sp);

rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_special_program", sp);

It should display the selected radio button value by using both #value in the field token.

Thank you,

Gian

client_21
Posted by mysteryminds on 20-Nov-2014 15:16

That worked like a charm Gian

Thanks so much....

I'm now left with only one thing the send mail trigger

if("{!R52185052.lock_status#value}"=="Locked" || "{!R52185052.lock_status#value}"=="Expired"||"{!R52185052.lock_status#value}"=="Cancelled")

{

if(("{!ficouw}"!="{!R77816268.before_fico}" || "{!co_borrower_ficouw}"!="{!R77816268.before_co_borrower_fico}" || "{!special_program#id}"!="{!R77816268.before_special_program#value}"))

{

return true;

}

else {return false;}

}

I think the IF condition is not working

I would like to send mails only when the fields highlighted are changed / modified / added for first time 

Currently whats happening is when the user is opening and file and just click on save the mail is shooting up 

Posted by Gian Torralba on 20-Nov-2014 15:31

Hello,

I just added the #value prefix to all field tokens. I also saw that you are comparing the #id prefix with the #value. Try placing this code on your email trigger.

if("{!R52185052.lock_status#value}"=="Locked" || "{!R52185052.lock_status#value}"=="Expired"||"{!R52185052.lock_status#value}"=="Cancelled")
{
    if(("{!ficouw#value}"!="{!R77816268.before_fico#value}" || "{!co_borrower_ficouw#value}"!="{!R77816268.before_co_borrower_fico#value}" || "{!special_program#value}"!="{!R77816268.before_special_program#value}"))
    {
        return true;
    }
    else
    {
        return false;
    }
}


Thank you,

Gian

Posted by mysteryminds on 20-Nov-2014 16:22

Gian

There seems to be errors shooting up with the previous update  

"var sp= rbv_api.getFieldValue("client6",{!id}, "special_program");
var sp= rbv_api.getValueById("client6", "special_program", sp);
rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_special_program", sp);"

in formula:var rbv_api = new Packages.com.rb.core.services.api.ServerSideAPI(51684403, 80425403);if("Locked"=="Locked" || "Locked"=="Expired"||"Locked"=="Cancelled"){var fi= rbv_api.getFieldValue("client6",109876359, "ficouw"); rbv_api.setFieldValue("client_21", 109876536, "before_fico", fi);var cf...

Posted by Gian Torralba on 20-Nov-2014 16:35

Hello,

What update did you do? You told me that it is working before? My last post where meant for the email trigger.

Thank you,

Gian

Posted by mysteryminds on 20-Nov-2014 16:45

Hi Gian

Remember  i've updated

var sp= rbv_api.getFieldValue("client6",{!id}, "special_program");
rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_special_program", sp);

WITH

"var sp= rbv_api.getFieldValue("client6",{!id}, "special_program");
var sp= rbv_api.getValueById("client6", "special_program", sp);
rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_special_program", sp);"

Then i received the mails with the exact data  in the email what I was expecting

The following fields have changed in this record:

Special Program 
Previous Value = 84757264
Current Value = VA SL

But in the front client screen people were having issues updating the fields  and not able to save. But once I've deactivated  the code the system works without issues.

But the mails are not giving the right values.

Posted by Gian Torralba on 20-Nov-2014 16:50

Hello,

"var sp= rbv_api.getFieldValue("client6",{!id}, "special_program");
var sp= rbv_api.getValueById("client6", "special_program", sp);
rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_special_program", sp);"


Please remove the quotes from the formula and please use the debug function in the trigger to check what is causing the issue. Debug it line by line.

Thank you,

Gian

"var sp= rbv_api.getFieldValue("client6",{!id}, "special_program");
var sp= rbv_api.getValueById("client6", "special_program", sp);
rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_special_program", sp);" - See more at: https://community.progress.com/community_groups/rollbase/f/25/p/14348/51819.aspx#51819
"var sp= rbv_api.getFieldValue("client6",{!id}, "special_program");
var sp= rbv_api.getValueById("client6", "special_program", sp);
rbv_api.setFieldValue("client_21", {!R77816268.id}, "before_special_program", sp);" - See more at: https://community.progress.com/community_groups/rollbase/f/25/p/14348/51819.aspx#51819
Posted by mysteryminds on 20-Nov-2014 17:04

Hi Gian

The funniest part is that its not throwing up any error when I run the DEBUG mode all runs fantastic from trigger perspective but in front end I see the error I've Posted above

Posted by Gian Torralba on 20-Nov-2014 17:32

Hello,

I see. You can try to add a handling in the getValueById(). It might be because of a null value in the sp variable.

Thank you,

Gian

This thread is closed