Prob with @formula

Hi there

Am experiencing problems with the code below. Trouble is after upgrading a database with the following code in it, the email notification doesn’'t seem to work 100% of the time (email isn’t always sent - seems to work okay if you’re on the same server as the mail-file of the person in the e-mail notification “name” field). Very weird.

Can anybody recommend a way around the problem?

lookup:=@If(@IsError(@DbLookup(“”:“NoCache”;“”;“Notification”;“E-mail Notification”;“Name”));@Return(null);

@DbLookup(“”:“NoCache”;“”;“Notification”;“E-mail Notification”;“Name”));

prompt:= @Prompt([Ok]; “Travel Requests”; “A request will now be sent to the travel manager”);

@If(prompt=1; @Do(

@Command([EditDocument];“1”);

@MailSend(lookup;“”;“”;“Travel Request To Action”;“”;“”; [IncludeDoclink]);

@PostedCommand([FileSave]);

@PostedCommand([FileCloseWindow])); “”)

Subject: prob with @formula

Return(null) may not execute the code further, if the first condition is true or error. So try replacing it with double quotes (“”) which makes the code continue. Then with null valkue if may be a problem for further execution of code.

Hence try this way:

lookup:=@If(@IsError(@DbLookup(“”:“NoCache”;“”;“Notification”;“E-mail Notification”;“Name”)); “” ; @DbLookup(“”:“NoCache”;“”;“Notification”;“E-mail Notification”;“Name”));

Try taking lookups into different variables like:

lookup1 := @DbLookup(“”:“NoCache”;“”;“Notification”;“E-mail Notification”;“Name”);

lookup1 := @If(@IsError(lookup1); “”; lookup1);

@If(lookup1 = “”; @Do(

lookup2 := @DbLookup(“”:“NoCache”;“”;“Notification”;“E-mail Notification”;“Name”);

lookup2 := @If(@IsError(lookup2); “”; lookup2)); “”);

REM “If both are null, then exits”

@If(lookup1 = “” & lookup2 = “”; @Return(“”); @Do(

lookup := @If(lookup1 = “” & lookup2 != “”; lookup2; lookup1);

prompt:= @Prompt([Ok]; “Travel Requests”; “A request will now be sent to the travel manager”);

@If(prompt=1; @Do(

@Command([EditDocument];“1”); @MailSend(lookup;“”;“”;“Travel Request To Action”;“”;“”; [IncludeDoclink] @PostedCommand([FileSave]); @PostedCommand([FileCloseWindow])))));

Subject: RE: prob with @formula

Thanks ever so much for your speedy & sound advice.

But I think what is really the problem is the action which I have in my outline - the send to mgr button does indeed work okay with the code I supplied from my views, apologies for my previous posting.

However, what I think is causing the trouble is the following action I have in the outline - it’s when the document is created with this method that the @mailsend doesn’t route correctly.

list:=“one person”:“a group”;

form:=@Prompt([OKCancelList]:[NoSort]:“Travel Request Type”;“The form is for: “;””;list);

@If(

form=“one person”;@Command([Compose];“Travelnew”);

form=“a group”; @Command([Compose];“Travelgroup”);

“”)

Your advice would be greatly appreciated.

Subject: RE: prob with @formula

See Yazdi’s comments, also I suspect the problem is that you’re trying to send an email with a doclink to a document that has not yet been saved for the first time. Since the document’s UNID is not finalized until it is saved, a link cannot be created until the save is completed.

@If(@Command([FileSave]);

 @Do(

      _tmp := @MailSend(lookup;"";"";"Travel Request To Action";"";""; [IncludeDoclink]);

      @If(@IsError(_tmp);

           @Prompt([ok]; "Mail send failure"; "Error sending mail: " + @Text(_tmp));

           ""

      );

      @Command([FileCloseWindow]);

 );

)

Subject: RE: prob with @formula

Hi Yazdi & Andre

Thanks very much for your posts & apologies for posting that 1st snippet of code as I don’t think the error lies there.

I definitely do want to save the doc & close it though. Would definitely agree with you that there’s no need to check the return value of the prompt.

I have that code in a standard form action & it works fine, my mistake. What doesn’t work is creating the same form from an action in the outline with the below code. I mean it creates the forms okay according to what’s picked but when I go to send for manager approval via the form action, the email is not sent & no ‘e-mail sent for delivery’ appears in the status bar when the form action button is clicked on. I know I’m being exceptionally thick - it works fine when I create the form from an action in a view but from the outline it simply doesn’t.

Would greatly appreciate what you think is going wrong in this scenario.

list:=“one person”:“a group”;

form:=@Prompt([OKCancelList]:[NoSort]:“Travel Request Type”;“The form is for: “;””;list);

@If(

form=“one person”;@Command([Compose];“Travelnew”);

form=“a group”; @Command([Compose];“Travelgroup”);

“”)

Subject: RE: prob with @formula

I’m now thinking that I may need to use @SetTargetFrame & @UpdateFormulaContext to try to resolve my problem. The above code is in an action in an outline in a frame postioned on the left-hand side. Not sure if I need this in the outline action or the action on the travel form (as per first code posting). Can a frame name be anything e.g. “view” or are there system-defined frame names which you shouldn’t use?

Thanks

Rob

Subject: RE: prob with @formula

That seems likely to solve the problem.

Subject: RE: prob with @formula

Hi Andre

Thanks for the advice. You’re a gent.

Guess what the problem was! No default view. Can’t believe I got flummoxed by that.

Got there in the end.

Rob

Subject: prob with @formula

Couple of tips for yr code,

NoCache makes Notes read the entire view again which can slow things down

read the @Dblookup into a variable and check the variable for @iserror

lookup:=@If(@IsError(@DbLookup(“”:“NoCache”;“”;“Notification”;“E-mail Notification”;“Name”));@Return(null);

@DbLookup(“”:“NoCache”;“”;“Notification”;“E-mail Notification”;“Name”));

prompt:= @Prompt([Ok]; “Travel Requests”; “A request will now be sent to the travel manager”);

@If(prompt=1; @Do(

@Command([EditDocument];“1”);

@MailSend(lookup;“”;“”;“Travel Request To Action”;“”;“”; [IncludeDoclink]);

@PostedCommand([FileSave]);

@PostedCommand([FileCloseWindow])); “”)

  1. You do not need to open the document in EDIT Mode to send mail, therefore you do not need the save and close commands either.

  2. @prompt([OK]… will always return 1 unless you are using other flags([YESNO],…) there is no need to check for the return value of prompt.

Yr code is probably failing on documents where you/user do not have author/edit access to open the document in editor.