NetTalk Central

Author Topic: prevent insert conditionally (Clarion 10, NT 11.04)  (Read 4754 times)

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
prevent insert conditionally (Clarion 10, NT 11.04)
« on: March 04, 2019, 12:17:44 PM »
     On a form, when accepting an Insert, I look into another file to see if a specific email address has been used before.  If so, I display an Alert warning to the user, that the email has been used.  I then return to the form, but it is no longer responsive.  That is, the Save button does not work, all I can do is cancel.  Here is my code, in the Validate, Insert, End embed:

If loc:Create_Login_Account = 1
   
    Usr:EMail = Phys:Physician_EMail_Address
    If Access:Users.Fetch(Usr:EMail_key) = Level:Benign  !check to see if account already exists
        !message that account exits
        p_web.Script('alert("Account(Email address) already exists!");')       
        Return('')       
    ELSE
        Usr:Institution_ID = Phys:Institution_ID
        Usr:Last_Name = Phys:Physician_Last_Name
        Usr:First_Name = Phys:Physician_First_Name
        Usr:MI = Phys:Physician_Middle_Initial
        Usr:Level = 50
        Usr:Salt = st.Random(8,st:upper)
        Usr:Password = st.Random(8,st:upper)
        Usr:EMail = Phys:Physician_EMail_Address
        Usr:ForcePasswordChange = 1
        Access:Users.Insert()
        !!loc vars for email control here
    END!IF
   
END

I'm not sure I'm using Return correctly.  Any suggestions?

Thanks,

Jeff King
« Last Edit: March 04, 2019, 05:32:30 PM by jking »

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: prevent insert conditionally (Clarion 10, NT 11.04)
« Reply #1 on: March 05, 2019, 12:34:04 AM »
Hi,

Normally I would do the checking in the ValidateAll embed of the form.
When the email-address already exists:

   Usr:EMail = Phys:Physician_EMail_Address
   If ~Access:Users.Fetch(Usr:EMail_key)  !check to see if account already exists
       LOC:ALERT = 'Account(Email address) already exists!'  ! = the message you want to show
       LOC:INVALID = 'Phys:Physician_EMail_Address'           ! = Email-address equate (points to the field in question)
       exit     ! Leave routine and show message
   end

This way, a popup alert or a message at the top of the screen will appear, depending on your app settings.

I know about (and follow) your quest to create a (mobile) app so probably a different approach is needed here.
But in a web based app I would do it like this.

Cheers,
Rene
Rene Simons
NT14.14

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Re: prevent insert conditionally (Clarion 10, NT 11.04)
« Reply #2 on: March 05, 2019, 03:55:29 AM »
Rene,

     Thanks!  I'll give this a try.  Note, this particular case is for a normal web based app, not the mobile app I'm still working on.

Jeff

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Re: prevent insert conditionally (Clarion 10, NT 11.04)
« Reply #3 on: March 05, 2019, 09:22:33 AM »
Rene,

  Your suggestion worked perfectly.  Thank you!

Jeff