Normal Topic Test for a new record. (Read 1438 times)
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Test for a new record.
Dec 18th, 2017 at 9:03pm
Print Post Print Post  
I want to send an email as I leave a newly created record in a file.   I know how to send the email, and I know how to set the parameters to trigger the sending of the email.

I think I want to send the email via an "On Form Exit" event, but how do I know the file is "new"?

  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Test for a new record.
Reply #1 - Dec 18th, 2017 at 9:09pm
Print Post Print Post  
@IsNew

You can also store a date and/or time the email was sent and check that. This can also come in handy for retrieves as that data will be when that record was first saved to the database.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Test for a new record.
Reply #2 - Dec 18th, 2017 at 10:22pm
Print Post Print Post  
I put the following programming in the On Form Exit location, but the programming is not triggering.  I put WriteLn statements in the programming to see how it was working.  One of them was right at the start of the programming, but nothing happened. 

Am I missing something?


var vMail as Int

Writeln("Start of Check")

If @IsNew and CheckSupplierIssue="YES"
{
        Writeln("Made it here")

     vMail = @SendMail("mail.diacom.com","Supplier Issue Identified"+ @Chr(13),"MaterialAlert@diacom.com",
     "paulc@diacom.com","","","This is an automatic message from the Sesame CORRECTIVE ACTION FILE. "+@newline()+  "Material: " + DCNumber + @NewLine() +Customer + "- has an issue: "+ BasicDescription ,"MaterialAlert@diacom.com","Diacom!146")
}
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Test for a new record.
Reply #3 - Dec 19th, 2017 at 2:23pm
Print Post Print Post  
Hi Paul,

Elsewhere in the programming for the form, are you calling FormCommit() or otherwise saving the record to the database?

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Test for a new record.
Reply #4 - Dec 19th, 2017 at 3:42pm
Print Post Print Post  
Ray, I don't use FormCommit(), but I have several places where I use @SelectTreeItem("Add Data Menu!Navigation!Save Record"). 

I use this command in five command buttons; Search, Save, AssignNumber, TableView and Sort.

I've tried adding a new record while insuring I don't click on any of these command buttons, but my programming in On Form Exit still doesn't get invoked.

Any other thoughts?
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Test for a new record.
Reply #5 - Dec 19th, 2017 at 4:32pm
Print Post Print Post  
Hmm... Is the value of CheckSupplierIssue actually the string value of YES or is it the Boolean value of Yes? One way to check which of the two statements is evaluating to false is to put these two lines into your programming.

Code
Select All
Writeln(@IsNew)
Writeln(CheckSupplierIssue="YES") 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Test for a new record.
Reply #6 - Dec 19th, 2017 at 9:46pm
Print Post Print Post  
Hello, Ray

I've learned a few things while playing around with this issue.

First, I have a "Next Record" command button with the following programming that was saving the file before exiting the form:

Var vNav as Int



If Not @ResultSetCurrentPosition() = @ResultSetTotal() and @Mode()=1
     {
     vNav = @SelectTreeItem("Search Update Menu!Navigation!Advance Record (F10)")
     }
If @ResultSetCurrentPosition() = @ResultSetTotal() and @Mode()=1
     {
     @Msg("There are No More Records In This Set")
     }
     
If @Mode()=0 
     {

     vNav = @SelectTreeItem("Add Data Menu!Navigation!Advance Record (F10)")
     }

The next thing I learned is that the @SendMail doesn't work if there are @NewLine commands as part of the message statement.  I was trying to format the message onto several lines. Not using @NewLine commands is not a big deal.

However, the last thing I discovered may be a problem for me.  One of the elements I want to keep in the message statement may be a multi-line text element.  Apparently the @SendMail command doesn't respond well to the embedded carriage returns.  Is there any trick to program around this behavior?

  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Test for a new record.
Reply #7 - Dec 20th, 2017 at 5:43pm
Print Post Print Post  
NHUser wrote on Dec 19th, 2017 at 9:46pm:
However, the last thing I discovered may be a problem for me.  One of the elements I want to keep in the message statement may be a multi-line text element.  Apparently the @SendMail command doesn't respond well to the embedded carriage returns.  Is there any trick to program around this behavior?


It could be that your mail server is very particular that the newlines be a Carriage Return And Line feed pair. (Newline() is just a Line Feed)

In that case you just need to do something like this

Code
Select All
vBody = "This is the body" + @Newline() + " With data on a few lines"
vBody = @Replace(vBody, @Chr(10), @Chr(13) + @Chr(10)) 



And use vBody in your SendMail() command.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Test for a new record.
Reply #8 - Dec 21st, 2017 at 2:37pm
Print Post Print Post  
Thanks, Ray

That last bit of programming took care of the issue!
  
Back to top
 
IP Logged