4 Replies Latest reply on Mar 31, 2014 5:35 PM by ziceg

    Global field restore issue

    ziceg

      I wonder if anyone could me figure out where I've gone wrong. It's a small issue that I assume has something to do a calculation in one of the scripts.

       

      Background

      I have the following:

      - an Assets Table with many items

      - a Request Table with a Request Items table (portal)

      - a Globals table with one field (g_SelectForOrder)

       

      I have a "Request" layout with a Button to "Select" (this uses the script iPad: Buttons: iPad | Select sample items request) , this then takes me to another window that will list all available items from "Assets" next to each Asset apart from details and image is a Checkbox image to "tick" (using on image the script iPad: Buttons: iPad | Checkbox set Field) if requried to be included in the Request so that numerous items can be selected at the same time. When the script is continued it creates new portal records into the request with the information stored in the global i.e. assets selected. This Asset record ID information was stored in the Global Field correctly, I can see them fine as a list.

       

      Generally the scripts are working and doing what they are supposed to do except that the first record created in the portal is blank which I assume has something to do with a "pilcro" in one of the formulas somewhere but not sure how to get it not to do it as I end up with an extra useless record.

       

      Appreciate any help I can get. Thanks

       

       

      iPad: Buttons: iPad | Select sample items request

      Set Variable [ $Request; Value:Requests::__kp_RequestID ]

      Set Field [ Globals::g_SelectForOrder; "" ]

      Go to Layout [ “Samples Selector | iPad Copy” (Assets) ]

      Show All Records

      Perform Find [ Specified Find Requests: Omit Records; Criteria: Assets::Ignore: “Y” ] [ Restore ]

      Sort Records [ Keep records in sorted order; Specified Sort Order: Assets::Type; ascending Assets::Description; ascending Assets::Serial Number; ascending ] [ Restore; No dialog ]

      Go to Record/Request/Page

      [ First ]

      #Pause script to allow user to select items they want to order via checkboxing into a global field

      Pause/Resume Script [ Indefinitely ]

      Go to Layout [ “Request_items_forLoop” (Requests_items) ]

      # Uses a loop to create portal records of selected items

      Freeze Window

      Set Variable [ $FindItem ]

      Loop

      New Record/Request Set Field [ Requests_items::_kf_RequestID; $Request ]

      #Need to FIX !!! it's entering first item as a blank then others OK. Maybe something to do with Pilcro?

      Set Field [ Requests_items::_kf_AssetID; GetValue (Globals::g_SelectForOrder ; $FindItem) ]

      Set Variable [ $FindItem; Value:$FindItem + 1 ]

      Exit Loop If [ $FindItem > ValueCount (Globals::g_SelectForOrder) ]

      End Loop

      Go to Layout [ “Requests | iPad” (Requests) ]

       

       

       

       

      iPad: Buttons: iPad | Checkbox set Field

      Set Field [ Globals::g_SelectForOrder; Case ( ValueCount ( FilterValues ( Globals::g_SelectForOrder ; Assets::Asset ID )) > 0 ; Substitute (Globals::g_SelectForOrder ; Assets::Asset ID & ¶; "" ) ; Globals::g_SelectForOrder & Assets::Asset ID & ¶ )]

        • 1. Re: Global field restore issue
          erolst

          ziceg wrote:

          iPad: Buttons: iPad | Select sample items request

          Show All Records // Unnecessary. A Find is always performed against all records (not a Constraint or an Extend, though …)

          Set Variable [ $FindItem ] // is empty ; Variable declaration before usage is unnecessary (in FM, at any rate)

          Loop

            New Record/Request

            Set Field [ Requests_items::_kf_RequestID; $Request ]

            #Need to FIX !!! it's entering first item as a blank then others OK. Maybe something to do with Pilcro?

            Set Field [ Requests_items::_kf_AssetID; GetValue (Globals::g_SelectForOrder ; $FindItem) ] // $findItem is empty at that point -> GetValue [ … ; undefined ] = empty result

            Set Variable [ $FindItem; Value:$FindItem + 1 ]

            Exit Loop If [ $FindItem > ValueCount (Globals::g_SelectForOrder) ]

          Read the comments added to the above script snippet. You need to switch these two lines:

           

          Set Field [ Requests_items::_kf_AssetID; GetValue (Globals::g_SelectForOrder ; $FindItem) ]

          Set Variable [ $FindItem; Value:$FindItem + 1 ]

           

          and the Exit Loop calculation should read

           

          Exit Loop If [ $FindItem = ValueCount (Globals::g_SelectForOrder) ]

           

          And maybe put Globals::g_SelectForOrder into a variable; makes the script a (microscopic) bit faster and lets you use a shorter reference.

          ziceg wrote:

          which I assume has something to do with a "pilcro" …

          It's called 'pilcrow', and there's no need to quote it …

          • 2. Re: Global field restore issue
            ziceg

            Thank you very much erolst.  I've now changed it as per below and works a treat

             

             

            Set Variable [ $Request; Value:Requests::__kp_RequestID ]

            Set Field [ Globals::g_SelectForOrder; "" ]

            Go to Layout [ “Samples Selector | iPad Copy” (Assets) ]

            Perform Find [ Specified Find Requests: Omit Records; Criteria: Assets::Ignore: “Y” ] [ Restore ]

            Sort Records [ Keep records in sorted order; Specified Sort Order: Assets::Type; ascending Assets::Description; ascending Assets::Serial Number; ascending ] [ Restore; No dialog ]

            Go to Record/Request/Page

            [ First ]

            #Pause script to allow user to select items they want to order via checkboxing into a global field

            Pause/Resume Script [ Indefinitely ]

            Go to Layout [ “Request_items_forLoop” (Requests_items) ]

            # Uses a loop to create portal records of selected items

            Freeze Window

            Loop

               Set Variable [ $Global; Value:Globals::g_SelectForOrder ]

               New Record/Request

               Set Variable [ $FindItem; Value:$FindItem + 1 ]

               Set Field [ Requests_items::_kf_RequestID; $Request ]

               Set Field [ Requests_items::_kf_AssetID; GetValue ($Global ; $FindItem) ]

               Exit Loop If [ $FindItem = ValueCount ($Global) ]

            End Loop

            Go to Layout [ “Requests | iPad” (Requests) ]

            • 3. Re: Global field restore issue
              erolst

              ziceg wrote:

              I've now changed it as per below and works a treat

               

              Glad to hear it. Let me just note that if you pack the global field value into a variable, don't do that within the loop body – it's only necessary once, before the loop starts.

              • 4. Re: Global field restore issue
                ziceg

                Oops, thanks have now moved that one to just before the Loop instead of just after.  Again many thanks for the help.