• 2 replies
  • Latest Post - ‏2013-05-29T19:44:42Z by GoodGulf
Claudio Palmeri
Claudio Palmeri
1 Post

Pinned topic Action Validation Hook on Date (PERL)

‏2013-05-24T09:32:36Z | clearquest hooks


Dear all,
I'm new about perl scripting hooks and i need to convert the BASIC hook below, that i did days ago (the hook check if the date inserted by the user is next than today): 
 Function Date_Validation(actionname, actiontype)
  ' actionname As String
  ' actiontype As Long
  ' Date_Validation As String
  ' action is Validate_DateField
  ' record type name is Request
  Dim today, DatePlanned
  today = now
  DatePlanned = GetFieldValue("DatePlanned").GetValue
  if ( DateDiff ("d", today, DatePlanned) < 0  ) Then
   Date_Validation = "DatePlanned: Insert a date next than today"
  end if
End Function
Have you got any suggestion where i can find some examples about this?
Thank you
Kind Regards 
Claudio Palmeri
  • DonaldN
    287 Posts

    Re: Action Validation Hook on Date (PERL)


    Hi Claudio,

    It is much easier to find a solution you treat it as a non-ClearQuest, as in, pure Perl, issue. Google will bring you many examples.

  • GoodGulf
    610 Posts

    Re: Action Validation Hook on Date (PERL)


    You are constrained by the modules provided with the version of per in ClearQuest.

    The easiest way to do this is by converting everything to epoch seconds, then it's just straight math.

    I forget what perl calls its validation routines so I'll call it date_val...

    sub date_val
      require "Time/";
      my ($result, $when);
      my $now     = time();
      my $daysecs = 60 * 60 * 24;
      # Assumes mm/dd/yyy hh:mm:ss
    #  my $DatePlanned = $entity->GetFieldStringValue("DatePlanned");
      my $DatePlanned = "4/29/2013 00:00:00";
      if ($DatePlanned =~ m#(\d+)/(\d+)/(\d+) (\d+):(\d+):(\d+)#)
        $when = Time::Local::timelocal($6, $5, $4, $2, $1-1, $3);
        $result = "Invalid date format";
      if (int (($when - $now)/$daysecs) < 0)
        $result = "DatePlanned: Insert a date next than today";
      return $result;