フィールド デフォルト値フック例

ユーザーがレコードを作成すると、Rational® ClearQuest® ソフトウェアは、レコードを作成して、そのフィールドを適切なデフォルト値に初期化します。特定のフィールドに、それに関連するデフォルト値フックがある場合は、そのフックが実行されてフィールド値が設定されます。フックがフィールドに関連付けられていない場合は、そのフィールド タイプに合ったデフォルト値が割り当てられます。 例えば、整数フィールドは 0 に設定され、文字列フィールドは空の文字列に設定され、リスト フィールドは空のリストに設定されます。 日付フィールドは、デフォルト値には初期化されません。日付フィールドには、常にデフォルト値フックを指定してください。

注: フックは管理者権限で実行されるので、これらの例は、フィールドの動作が読み取り専用の場合でも動作します。

次の例は、日付フィールドを現在の日付と時刻に初期化する方法を示します。

VBScript

Sub submit_date_DefaultValue(fieldname)

    ' fieldname As String
    ' entityDef = defect
    call SetFieldValue(fieldname, now)

End Sub 

Perl

# Define a function for the current timestamp

sub GetCurrentDate {

    my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $time) =
      localtime();
    return sprintf("%4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", $year + 1900, 
      $mon + 1, $mday, $hour, $min, $sec);
}

# Define a routine to call the timestamp function

sub Submit_Date_DefaultValue {

   my($fieldname) = @_;
   # $fieldname as a string scalar and entityDef is Defect
   $entity->SetFieldValue($fieldname, GetCurrentDate());

} 

次の例では、「submitter」フィールドを、レコードの登録者のログイン名で初期化します。

VBScript

Sub submitter_DefaultValue(fieldname)

    ' fieldname As String
    ' entityDef = swbug

    SetFieldValue fieldname, GetSession().GetUserLoginName()

End Sub 

Perl

sub Submitter_DefaultValue {

    my($fieldname) = @_;

    # $fieldname as a string scalar

    # entityDef is Defect

    my $session;

    my $username;

    $session = $entity->GetSession();

    $username = $session->GetUserLoginName();

    $entity->SetFieldValue($fieldname, $username);

} 

フィードバック