9 Replies Latest reply on Dec 14, 2016 1:51 PM by David Moyer

    Update Script ( Date Issue)

    ZoocMan85

      Hey Everyone,

       

      So i have an update script that pulls a .zip file from  a webserver based on dates. However, im having issues with my IF statement to trigger the update.

       

      script.jpg

       

      screenshot.jpg

       

      So basically this scipt would trigger if my installed Revision was December 13,2016 however these are both text fields and it sees the 1 after december in both fields so it shows as no update. How can i fix this? Thanks

        • 1. Re: Update Script ( Date Issue)
          David Moyer

          mmmm. Brew.

          Hi,

          It looks you need to parse the dates out of the revision titles and convert those into dates that FM can compare.  It's not a small problem, but I'm guessing somebody is already working on it.

          • 2. Re: Update Script ( Date Issue)
            ZoocMan85

            Dave,

             

            What is the easiest way to parse the data out of both fields ?

            • 3. Re: Update Script ( Date Issue)
              David Moyer

              I'm debugging something now.

              • 4. Re: Update Script ( Date Issue)
                erolst

                Let ( [

                  string = "masterlist.zip,March 1 2016" ;

                  stringList = Substitute ( string ; "," ; ¶ ) ;

                  stringDate = GetValue ( stringList ; 2 ) ;

                 

                  monthString = LeftWords ( stringDate ; 1 ) ;

                  monthList = "January¶February¶March¶April¶May¶June¶July¶August¶September¶October¶November¶December" ;

                 

                  monthDigits = ValueCount ( Left ( monthList ; Position ( monthList ; monthString ; 1 ; 1 ) ) ) ;

                  monthDigits = SerialIncrement ( "00" ; monthDigits ) ;

                 

                  dayDigits = MiddleWords ( stringDate ; 2 ; 1 ) ;

                  dayDigits = SerialIncrement ( "00" ; dayDigits ) ;

                 

                  yearDigits = Right ( string ; 2 )

                  ] ;

                  GetValue ( stringList ; 1 ) & "," & yearDigits & monthDigits & dayDigits

                )

                 

                yields “masterlist.zip,160301”.

                 

                Tweak the logic al gusto, then delete the first variable declaration, put it into a Custom Function with the parameter 'string', and you're ready to go.

                 

                There is possibly some faster way by rearranging the date components and passing them into GetAsDate( ), but I don't have a file created with US date format to test this.

                2 of 2 people found this helpful
                • 5. Re: Update Script ( Date Issue)
                  David Moyer

                  This should work as a way to extract the date from a single revision title:

                  Let(
                    [
                      textDotDate = Main::text1;
                      comma = Position ( textDotDate; ","; 1; 1 );
                      textDate = Right ( textDotDate; Length ( textDotDate ) - comma );
                      mon = Lower ( Left ( LeftWords ( textDate; 1 ); 3 ) );
                      monthNum = ( Position ( "jan feb mar apr may jun jul aug sep oct nov dec"; mon; 1; 1 ) + 3 ) / 4;
                      dayPart = MiddleWords ( textDate; 2; 1 );
                      yearPart = RightWords ( textDate; 1 )

                    ];
                    If ( comma > 0 and monthNum > 0;
                      Date ( monthNum; dayPart; yearPart );
                      ""
                    )
                  )

                  Edit:  I now see your revision string a bit better with my specs.  I adjusted the search string in the "dot" calculation above.  It's now called "comma".

                  1 of 1 people found this helpful
                  • 6. Re: Update Script ( Date Issue)
                    ZoocMan85

                    Not to sound dumb guys but am i setting this in 2 separate fields as calcs ?

                    • 7. Re: Update Script ( Date Issue)
                      ZoocMan85

                      Niceeee. Got it Dave.

                      • 8. Re: Update Script ( Date Issue)
                        David Moyer

                        I love a puzzle.  To answer your question, yes, I think two calculated fields are in order.

                        1 of 1 people found this helpful
                        • 9. Re: Update Script ( Date Issue)
                          David Moyer

                          erolst wrote:

                            stringList = Substitute ( string ; "," ; ¶ ) ;

                            stringDate = GetValue ( stringList ; 2 ) ;

                          This is a better way to parse the date side of the string.