4 Replies Latest reply on Oct 27, 2016 1:44 PM by yasirali

    script trigers on start-up window

    yasirali

      Hi all

      I'm using file maker 13 and trying to create a data base for multiple users on the web with a privilege set. and it would also be controlled by two people with full access privilege.

      one of the requirement is to set a lay out for the members where the would be able to submit requests to the full access privilege people. and a message should pop-up on the Admin (full access) start-up window when a new query is submitted, also a message should pop-up on the member's who submitted the query  start-up window when  the request is answered.

      I wrote a script that obviously didn't work, it looks so complicated to me,

      set Error Capture [on]   
      If [Get (AccountPrivilegeSetName) = "[Full Access]"]  
      Go to layout ["Query"(Query)]  
      Enter find mode   Set Field [Query::query_status; "Active" ]  
      perform find     if [Get (LastError) = 0]    
      go to layout ["Home"(members)]    
      show custom dialog [" New Queries" ; "You have" & Get ( FoundCount ) & "queries"]    
      perform script ["find active queries"]      
      Else If [Get (LastError) / 0]      
      go to layout ["Home"(members)]      
      show custom dialog [" New Queries" ; "You don't have active queries"]      
      End If 
      End If 
      set Error Capture [off] 
      set Error Capture [on] 
      If [Get (AccounName) = Query::email_query] 
      go to layout ["query"(query)] 
      Enter find mode 
      Set Field [Query::email_query;Get( AccountName )] 
      Set Field [Query::status_query; "Answered"]  
      show custom dialog ["Queries" ; "Your request was answered"] 
      Go to layout ["Home"(members)] 
      Enter find mode 
      Set Field [Home::email_address;Get( AccountName )] 
      perform find 
      enter browse mode 
      If [Get (LastError) + 0] 
      Go to layout ["Home"(members)] 
      Enter Find Mode 
      Set Field [Home::email_address;Get( AccountName )] 
      perform find 
      enter browse mode 
      End If 
      End If 
      set Error Capture [off] 
      Exit Script

       

      I would really appreciate any help or  suggestion if you were able to find what's wrong

        • 1. Re: script trigers on start-up window
          philmodjunk

          "did not work" doesn't tell us HOW it didn't work.

           

          The first thing that I see is that for Admin users, you are finding all Active Queries twice. You only need to find them once so that part of your script makes no sense.

           

          You also need to use Else IF in your script to keep code for non full access users separate from full access users:

           

          If [ Get ( AccountPrivilegeSetName ) = "[Full Access]

             #code to find open queries goes here

           

          Else If [ Get ( AccountPrivilegeSetName ) <> "[Full Access]"

              #Code for handling "answered queries for a given user goes here

           

          End IF

          • 2. Re: script trigers on start-up window
            mikebeargie

            your script is rife with errors and I agree you've overcomplicated it.

             

            a few errors annotated for you:

            set Error Capture [on]


            If [Get (AccountPrivilegeSetName) = "[Full Access]"]
               Go to layout ["Query"(Query)]
               Enter find mode

               Set Field [Query::query_status; "Active" ]
               perform find

               if [Get (LastError) = 0]
                  go to layout ["Home"(members)]
                  show custom dialog [" New Queries" ; "You have" & Get ( FoundCount ) & "queries"]
                  perform script ["find active queries"]
               Else If [Get (LastError) / 0]
                  go to layout ["Home"(members)]
                  show custom dialog [" New Queries" ; "You don't have active queries"]
               End If

              Exit Script //Exit here since you are done with full access process.
            End If


            set Error Capture [off]
            set Error Capture [on]

             

            Go to layout ["Query"(Query)] //Need to be on query layout to find/evaluate it.


            If [Get (AccountName) = Query::email_query] //This isn't needed, because you're doing a find for the user right???
               go to layout ["query"(query)]
               Enter find mode
               Set Field [Query::email_query;Get( AccountName )]
               Set Field [Query::status_query; "Answered"]
               show custom dialog ["Queries" ; "Your request was answered"]
               Go to layout ["Home"(members)]
               Enter find mode
               Set Field [Home::email_address;Get( AccountName )]
               perform find
               enter browse mode // browse mode not needed after doing a find.
               If [Get (LastError) + 0] // Get(LastError) = 0 ??? or Get(LastError) <> 0 ???
                  Go to layout ["Home"(members)]
                  Enter Find Mode
                  Set Field [Home::email_address;Get( AccountName )]
                  perform find
                  enter browse mode
               End If
            End If


            set Error Capture [off] //Not needed unless you're running another script.
            Exit Script //Not needed unless you need to get a result from the script for another script.

             

            You have a number of unnecessary script steps I crossed out. Whenever you use Get(LastError), you should never use division or addition for it, just = or <> for not equals.

             

            I am assuming that the second "IF" group fails because Get(AccountName) is never matching Query::email_query. I don't even think you need to wrap that chunk in an "IF" since you're just finding the user and using an IF depending on the result.

            • 3. Re: script trigers on start-up window
              mikebeargie

              Also switch these two lines:

                    go to layout ["Home"(members)]

                    show custom dialog [" New Queries" ; "You have" & Get ( FoundCount ) & "queries"]

               

              Otherwise you will see the found count of your home layout, and not for the find you just did.

              • 4. Re: script trigers on start-up window
                yasirali

                Thank you for your answers

                they were really helpful

                I followed your advises and also found that another error was happening when I set a field to look for an email address that has the @ sign and forgot to put "==" before it.

                I did that too and Know it works pretty good