Link to home
Start Free TrialLog in
Avatar of AliciaVee
AliciaVee

asked on

Easy Question? Check @IF Formula Syntax

Experts,

The following code sends the emails, but does not update the hidden field [EditSentFlag] to Yes.  By default, the document is set to EmailSentFlag=No.  Only if the field BDCEmail is checked, then emails are sent (there are 3 values for BDCEmail).  The values are retrieved from hidden fields, at the top of the form, computed, eacj using @GetProfileField("DbProfile";"BDC3")

Since there will be future edits on this main document -- I only want the email to be sent the very first time, and only if the specific field is checked (at least half of the time, this alert will not be sent from this particular form.

What is wrong with my @If statement that is it not allowing my EmailSentFlag to be updated with YES if the condition is true?  Also, please verify that all of these conditions can be true -- or should I be using Case Select?  (confused??)

@If(EmailSentFlag="No" & @Contains(BDCEmail;"BDC1"); @MailSend(BDC1;DbAdmin;Null;"New Literature Submitted";"New Literature has been submitted by "+ DocAuthor+@NewLine+"Please click the link to view the submission and take the required action for group notification --> ";Null;[IncludeDoclink]);
@SetField(EmailSentFlag;"Yes"));
@If(EmailSentFlag="No" & @Contains(BDCEmail;"BDC2"); @MailSend(BDC2;DbAdmin;Null;"New Literature Submitted";"New Literature has been submitted by "+ DocAuthor+@NewLine+"Please click the link to view the submission and take the required action for group notification --> ";Null;[IncludeDoclink]);
@SetField(EmailSentFlag;"Yes"));
@If(EmailSentFlag="No" & @Contains(BDCEmail;"BDC3"); @MailSend(BDC3;DbAdmin;Null;"New Literature Submitted";"New Literature has been submitted by "+ DocAuthor+@NewLine+"Please click the link to view the submission and take the required action for group notification --> ";Null;[IncludeDoclink]);
@SetField(EmailSentFlag;"Yes"))

Please rush -- I know, past couple of days all of my Qs have been rush rush :(

Thanks in advance,
AliciaVee
Avatar of qwaletee
qwaletee

First, easier if you structure the format of the code:

@If(
    EmailSentFlag="No" & @Contains(BDCEmail;"BDC1");
        @MailSend(
            BDC1;DbAdmin;Null;"New Literature Submitted";
            "New Literature has been submitted by "+ DocAuthor+@NewLine+"Please click the link to view the submission and take the required action for group notification --> ";
            Null;[IncludeDoclink]
        );
    @SetField(EmailSentFlag;"Yes")
);

@If(
    EmailSentFlag="No" & @Contains(BDCEmail;"BDC2");
        @MailSend(
            BDC2;DbAdmin;Null;"New Literature Submitted";
            "New Literature has been submitted by "+ DocAuthor+@NewLine+"Please click the link to view the submission and take the required action for group notification --> ";
            Null;[IncludeDoclink]
        );
    @SetField(EmailSentFlag;"Yes")
);

@If(
    EmailSentFlag="No" & @Contains(BDCEmail;"BDC3");
        @MailSend(
            BDC3;DbAdmin;Null;"New Literature Submitted";
            "New Literature has been submitted by "+ DocAuthor+@NewLine+"Please click the link to view the submission and take the required action for group notification --> ";
            Null;[IncludeDoclink]
        );
    @SetField(EmailSentFlag;"Yes")
)

Now, this may be your problem.  You misunderstand the way @If works.  You have three separate @If statements.  In each case, you have three parameters:

1) condition (based on EmailSentFlag=No and some content in BDCEmail field
2) mailsend
3) setfield

So, if I can paraphrase:
@If(  condition    ;   mailsend    ; setfield)

I THINK you are assuming that if condirion is true, both mailsend and setfield get executed, i.e., each if will do one of two things:
1) it will be skipped if the condition is false
2) if teh condition is true, it will send a message AND it will set the field to Yes

That's not so.  A 3-parameter @If is really

@If(1;2;3) -- 1 is the condition, 2 is what to do if true, 3 is "else" (i.e., what to do if condition is false.

So, I think you really wanted something different...

@If(
    EmailSentFlag = "Yes";
        @Return(FAKE_STATEMENT_SKIP_ALL_THIS);
    BDCEmail = "BDC1";
        @MailSend(....);
    BDCEmail = "BDC2";
        @MailSend(....);
    BDCEmail = "BDC3";
        @MailSend(....);
    @Return(
        @Prompt([OK]; "Error [ELSE STATEMENT]"; "Unexpected condition -- EmailSentFlag=No and BDCEmail does notmatch known values BDC1/2/3")
    )
);
FIELD EmailSentFlag := "Yes"; REM "We ALWAYS set this -- either it was already Yes and the @Return(FAKE) stopped the rest of the formula, or one of the three BDC statements matched and e-Mail was sent and then it got here, or @Return(@Prompt) stopped the rest of the formula.  So, if we got here, a message WAS sent.";
Avatar of AliciaVee

ASKER

qwaletee,

Wow!  Great explanation -- thank you thank you!  Yep -- you were right in the way my little head was thinking.  It is because I have some VBA experience with MS Access dbs -- I get confused and am having a hard time trying to stay focused on Notes, and that language.  But with your help (and other EEs) I am getting there.  Your explanation of how this is supposed to work makes excellent sense.  Stuff I can't learn in books :(

I will try as you suggested (and yes, I really have to learn how to write better code layout.  Sometimes when I try to enter in my code window, I get an error like I'm not supposed to split certain parts of the code -- still trying to figure that out).

Anyway -- one question.  For the @Return part...am I supposed to enter what you have?  (FAKE_STATEMENT_SKIP_ALL_THIS);

Okay...will try that.
;)
qwaletee,

Okay, I added your code -- as is -- no changes.  the EditSentFlag is not updating to Yes.  Also, only one email gets sent.  So, if in BDCEmail FIELD -- there are 3 checked boxes, 3 emails should be sent.  The BDCEmail values are coming from hidden fields that are populated based on a profile doc.  In my previous code, that part was working, but the EditFlag was not getting updated to yes.

Help.....
qwaletee ,

Okay -- I've tweaked this a little.  Instead of a hidden field, I am using a combo drop down list to select whether an email should be sent or not Yes or No.

Now, it is working and I have the option to change it to NO -- if I have to go back into the document to make changes (leveraging your other solution you provided for the request form in another post.  This is actually the Main parent document -- the other document is the response doc).

Anyway, now what happens is that only one email gets sent, even if I check off all three choices (each choice is a specific person in a department -- and not all 3 should be informed of new literature).

This is what I have in PostSave event:

@If(
    EmailSentFlag = "No";
        @Return(FAKE_STATEMENT_SKIP_ALL_THIS);
    BDCEmail = "BDC1";
        @MailSend(BDC1;DbAdmin;Null;"New Literature Submitted";
            "New Literature has been submitted by "+ DocAuthor+@NewLine+"Please click the link to view the submission and take the required action for group notification --> ";
            Null;[IncludeDoclink]
);
    BDCEmail = "BDC2";
        @MailSend(BDC2;DbAdmin;Null;"New Literature Submitted";
            "New Literature has been submitted by "+ DocAuthor+@NewLine+"Please click the link to view the submission and take the required action for group notification --> ";
            Null;[IncludeDoclink]
);
    BDCEmail = "BDC3";
        @MailSend(BDC3;DbAdmin;Null;"New Literature Submitted";
            "New Literature has been submitted by "+ DocAuthor+@NewLine+"Please click the link to view the submission and take the required action for group notification --> ";
            Null;[IncludeDoclink]
);
    @Return(
        @Prompt([Ok]; "Error [ELSE STATEMENT]"; "Unexpected condition ")
    )
)

By the way, I'm not sure if I am supposed to edit/add/remove the [ELSE STATEMENT] text above -- or is that part of the code?

AliciaVee
AliciaVee,

> Anyway -- one question.  For the @Return part...am I supposed to enter what you have?  
> (FAKE_STATEMENT_SKIP_ALL_THIS);

In VB (and LotusScript), you can have an empty executable section of an IF or ELSE.  Not so with @If. Therefore, you have to put in something.  I put in a fake variable, which, since it holds no value, evaluates to an empty string, which effectively has no action.  So, the following are equivalents:

If someCondition Then
Else
    Print "false"
End If

@If(someCondition;
    EMPTY_CLASE_THIS_IS_A_FAKE_VARIABLE;
  @Prompt([ok]; ""; "false")
)


The @Return cuases teh formula to stop evaluating immediately.

- qwaletee
ASKER CERTIFIED SOLUTION
Avatar of qwaletee
qwaletee

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
qwaletee,

You bring up a good point -- does it make sense have this many flags?  Well, for this particular need, there are really 3 different departments that get notified, but will keep it in mind for futuere apps.

thanks!