4 Replies Latest reply on Dec 22, 2009 8:56 AM by philmodjunk

    How do I get the Add Contact or Add group Script in Campaign to stop at 100 loop count?

    jamesdalbright_1

      Title

      How do I get the Add Contact or Add group Script in Campaign to stop at 100 loop count?

      Post

      I am using FMP 9 Advanced on a MAC. I put the entire Add Contact or Add Group Records script into a loop and it adds the found list to the Campaigns Recipients Tab portal window. Now, I am trying to figure out how to stop the loop in the Add Contact or Add Group Records at 100?

      Thanks. 

        • 1. Re: How do I get the Add Contact or Add group Script in Campaign to stop at 100 loop count?
          HugoLidia
            

          You'd need to setup a variable to hold your loop count.  At the start of the loop, check the variable value is set to zero, at end of loop increment by 1 and check if variable value is now greater than 100, in which case exit the loop, else continue loop.

           

          Set Field ["Global","0"]
          Loop
          New Record/Request
          Set Field ["Global","Global + 1"]
          Exit Loop if ["Global = 100"]
          End Loop

          • 2. Re: How do I get the Add Contact or Add group Script in Campaign to stop at 100 loop count?
            philmodjunk
              

            The script example posted by HugoLida will work, but you might prefer this slightly different approach so that you don't have to declare a field just to count the loops:

             

            Set Variable [$I,Value: 0]
            Loop
              New Record/Request
              Set Variable $I; Value: $I + 1]
              Exit Loop if [$I = 100]
            End Loop

            • 3. Re: How do I get the Add Contact or Add group Script in Campaign to stop at 100 loop count?
              jamesdalbright_1
                

              When I added the following to the script below it did not stop at 100 and it changed all of the contact IDs to 1 in the contact ID field in the portal in the Recipients Tab in the Campaigns Form View Layout. Can you tell me how to change this to make it add only 100 with out changing the IDs? Thanks for your help. 

               

               

              Set Variable [$I,Value: 0]

              Loop

              New Record/Request
                Set Variable $I; Value: $I + 1]
                Exit Loop if [$I = 100]
              End Loop

              Loop

              Allow User Abort [Off]

              Set Error Capture [On]

              Set Field [Campaigns::Temp Contact ID Global; ""]

              If [Get(ScriptParamater)="contact"]

              Set Field [Campaigns::Temp Contact ID Global; campaigns_campaigncontacts_Contacts::Contact ID & "return symbol"]

              End if

              If [Get(ScriptParameter)= "group"]

              Go to Related Record [Show only related records; From table "Groups_Contacts"; Using Layout: "Select List -Contacts" (campaigns_campaigncontacts_Contacts)]

              Loop

              Set Field [Campaigns::Tmep Contact ID Global; campaigns_campaigncontacts_Contacts:Contact ID & "return sign" & Campaigns::Temp Contact ID Global]

              Go to Record/ Request/Page [Next; Exit after last]

              End Loop

              End If

              Go to Layout ["CampaignContacts Utility" (CampaignContacts)]

              Loop

              Exit Loop If [Campaigns::Temp Contact Id Global = ""]

              Enter Find Mode[]

              Set Field [Campaigncontacts::CampaignID; Campaigns::Temp Campaign ID Global & "l" & Left Words(Campaigns::Tmep Contact ID Global; 1)]

              Perform Find []

              If [Get (FoundCount) = 0]

              New Record/Request

              Set Field [CampaignContacts::Campaign ID; Campaigns::Tmep Campaign ID Global]

              Set Field [CampaignContacts::Contact ID; LeftWords(Campaigns::Temp contact ID Global; 1)]

              End if 

              Set Field [Campaigns::Temp Contact ID Global; Substitute(Campaigns::Temp Contact ID Global; LeftWords(Campaigns:Temp Contact ID Global; 1) & "return sign"; "")]

              End Loop

              Perform Script ["Navigate to Contacts Forums" Parameter:"campaign"

              Go to Field [campaigns_campaigncontacts_Contacts::Full Name]

              Commit Records/Requests [Skip data entry validation: No dialog]

              Go to Layout ["Select List - contacts" (campaigns_campaigncontacts_Contacts)]

              Go to Record/RequestPage [Next: Exit after Last]

              End Loop

              Go to Layout ["Form View Camp;align" (Campaigns)]

               

               

              • 4. Re: How do I get the Add Contact or Add group Script in Campaign to stop at 100 loop count?
                philmodjunk
                  

                jamesdalbright,

                 

                We were expecting you to modify the existing loop with either a global field or a variable being used as a counter that counts up to 100 not just to insert the code into the beginning of your script. When you do that the script simply makes 100 new records as you discovered.

                 

                When I look at your script (which I've cleaned up and indented to make more readable), I see multiple loops which are nested inside one another. Which loop do you want to have execute no more than 100 times?


                Loop

                  Allow User Abort [Off]

                  Set Error Capture [On]

                  Set Field [Campaigns::Temp Contact ID Global; ""]

                  If [Get(ScriptParamater)="contact"]

                    Set Field [Campaigns::Temp Contact ID Global; campaigns_campaigncontacts_Contacts::Contact ID & "¶"]

                  End if

                  If [Get(ScriptParameter)= "group"]

                    Go to Related Record [Show only related records; From table "Groups_Contacts"; Using Layout: "Select List -Contacts" (campaigns_campaigncontacts_Contacts)]

                    Loop

                      Set Field [Campaigns::Tmep Contact ID Global; campaigns_campaigncontacts_Contacts:Contact ID & "¶" & Campaigns::Temp Contact ID Global]

                      Go to Record/ Request/Page [Next; Exit after last]

                    End Loop

                  End If

                  Go to Layout ["CampaignContacts Utility" (CampaignContacts)]

                  Loop

                    Exit Loop If [Campaigns::Temp Contact Id Global = ""]

                    Enter Find Mode[]

                    Set Field [Campaigncontacts::CampaignID; Campaigns::Temp Campaign ID Global & "l" & Left Words(Campaigns::Tmep Contact ID Global; 1)]

                    Perform Find []

                    If [Get (FoundCount) = 0]

                      New Record/Request

                      Set Field [CampaignContacts::Campaign ID; Campaigns::Tmep Campaign ID Global]

                      Set Field [CampaignContacts::Contact ID; LeftWords(Campaigns::Temp contact ID Global; 1)]

                    End if 

                    Set Field [Campaigns::Temp Contact ID Global; Substitute(Campaigns::Temp Contact ID Global; LeftWords(Campaigns:Temp Contact ID Global; 1) & "¶"; "")]

                  End Loop

                  Perform Script ["Navigate to Contacts Forums" Parameter:"campaign"

                  Go to Field [campaigns_campaigncontacts_Contacts::Full Name]

                  Commit Records/Requests [Skip data entry validation: No dialog]

                  Go to Layout ["Select List - contacts" (campaigns_campaigncontacts_Contacts)]

                  Go to Record/RequestPage [Next: Exit after Last]

                End Loop

                Go to Layout ["Form View Camp;align" (Campaigns)]