定義済みのフォームのオープン

GSU_CQXE_OpenForm と GSU_CQXE_OpenSubmitForm のグローバル フックにより、フックから定義済みのフォームを開くことができます。スキーマにグローバル フックを追加した後は、それにアクセスしてフォームのレコード タイプを指定し、フィールド値でそれを初期化することが可能です。

グローバル フック コードのダウンロード手順については、http://www.ibm.com/support/docview.wss?&rs=939&uid=swg21432968 のテクニカル ノート 1432969 を参照してください。

この機能は、ClearQuest Eclipse および ClearQuest Web のクライアントで使用可能です。ユーザーが古いクライアントまたは ClearQuest for Windows クライアントからフォームを開こうとすると、API は情報メッセージを返します。 ユーザーにこのメッセージを表示するには、die 関数を呼び出します。

クライアントがこの機能をサポートしている場合は、API は例外をスローし、API 呼び出しの後のコードはすべて実行されません。API 呼び出しの後に追加でコードを実行するには、スクリプトでコールバック フックを使用します。

例

ユーザーに定義済みのフォームを提供するには、これらの、レコード スクリプトおよびアクション スクリプトの例をグローバル フックで使用します。この例では、CreateChildDefect アクションが Record Script フックからの値で定義されたフォームを開きます。ユーザーは、RecordScriptCancel フックと RecordScriptSave フックでコードを実行するフォームをキャンセルまたは保存することができます。

この例を使用するには、スキーマに次の変更を加えます。
  1. 障害レコード タイプに、dateTime という名前の DATE_TIME フィールドと、children という名前の REFERENCE_LIST フィールドの、2 つのフィールドを新規に追加します。
  2. children フィールドの [参照先] 属性を [障害] に設定します。
  3. 以下の、Perl または VBScript コードの例を使用して、RecordScript、RecordScriptSave、および RecordScriptCancel という名前の 3 つのレコード スクリプトを作成します。
  4. CreateChildDefect という名前の、新しい RECORD_SCRIPT_ALIAS アクションを障害レコード タイプに追加します。CreateChildDefect アクションを、上記で作成した RecordScript フックを使用するように設定します。
  5. 障害レコード タイプの Defect_Base フォームに、OpenForm という名前のタブを新規に追加します。
  6. 新しい OpenForm タブに、次のコントロールを追加します。
    • [日付] と [時刻] の両方を表示するよう設定した [テキスト フィールド]。 日付の表示形式に [長い形式の日付] を選択します。 ソース フィールドに [日付/時間] を選択します。
    • ソース フィールドを [子] に設定した [親/子] コントロール。
注: これらのコード例では、API によって返されたエラー メッセージに対応するために DieWithCustomMessage 関数を使用するものもあります。このグローバル スクリプトについて詳しくは、「カスタム エラー メッセージの生成」を参照してください。

Perl 例

sub Defect_RecordScript {
    my($result);
    my($param) = @_;
    # record type name is Defect
    
    $currentSession = $entity->GetSession();    
    $newentity = $currentSession->BuildEntity("Defect");
    $headline = $entity->GetFieldStringValue("Headline");
    $id = $entity->GetFieldStringValue("id");

    $newentity->SetFieldValue("Headline", "Child Of [".$id."] ".$headline); 
    $newentity->SetFieldValue("Severity", "3-Average"); 
    
    # For multiple-line (Choice list) values
    $newentity->SetFieldValue("Symptoms", "Data Loss\nSlow Performance");
    
    # For reference-list fields
    $newentity->AddFieldValue("customer", "Anne Johnson");
    $newentity->AddFieldValue("customer", "Ethan Hunt");

    # For Date fieldType
    $newentity->SetFieldValue("dateTime", "2010-04-08 15:57:28"); 
    
    # For multiple-line (textArea) fieldType, support "\n","\t"special characters
    $newentity->SetFieldValue("Description", "Description"); 
  
    # Set the orders of the fields, must include all field names 
    $fieldNames = ["Headline","Severity","Symptoms","customer","dateTime","Description"];
    $returnValue = GSU_CQXE_OpenSubmitForm($newentity, "RecordScriptSave", "RecordScriptCancel", $fieldNames);
    
    if($returnValue){
        # If the client doesn't support the global hook, execute the hooks there, 
        # e.g. validate and submit $newentity
    }
    return $result;
}
sub Defect_RecordScriptSave {
    my($result);
    my($param) = @_;
    # record type name is Defect
        
    @params = split (/\n+/, $param);
    $entity->EditEntity("Modify");
    $entity->AddFieldValue("children",$params[1]);
    $entity->Validate();
    $entity->Commit(); 
    return $result;
}
sub Defect_RecordScriptCancel {
    my($result);
    my($param) = @_;
    # record type name is Defect        
    
    $error_summary="CancelBackSaveHook";
    $error_details="No params!";
    DieWithCustomMessage("INFO", $error_summary, $error_details);
  
    return $result;
}

VBScript 例

Function Defect_RecordScript(param)
  ' param As Variant
  ' record type name is Defect
  Dim currentSession
  Dim newentity
  Dim this_entity
  Dim fieldOrder
  Dim returnValue
  Dim saveHookName
  Dim cancelHookName

  set currentSession = GetSession	
  set newentity= currentSession.BuildEntity ("defect")
  
  newentity.SetFieldValue "Headline", "Child Of parent record " 
  newentity.SetFieldValue "Severity", "3-Average" 
  
  ' For multiple-line (Choice list) values
  newentity.SetFieldValue "Symptoms", "Data Loss\nSlow Performance" 
  
  ' For reference-list fields
  newentity.AddFieldValue "customer", "Anne Johnson"
  newentity.AddFieldValue "customer", "Ethan Hunt"

  ' For Date fieldType
  newentity.SetFieldValue "dateTime", "2010-04-08 15:57:28" 
  	
  ' For multiple-line (textArea) fieldType, support vbcrlf special characters
  newentity.SetFieldValue "Description", "Data Loss" & vbcrlf & "Slow Performance Unexpected Behavior" & vbcrlf & "retr" 

  ReDim fieldNames(6)
  fieldNames(0)="Headline"
  fieldNames(1)="Severity"
  fieldNames(2)="Symptoms"
  fieldNames(3)="customer"
  fieldNames(4)="dateTime"
  fieldNames(5)="Description"

saveHookName="RecordScriptSave"
  cancelHookName="RecordScriptCancel"
  Defect_RecordScript = GSU_CQXE_OpenSubmitForm(newentity,saveHookName,cancelHookName,fieldNames)
  If Defect_RecordScript <> "" then
  ' If the client doesn't support the global hook, excute the hooks there, 
  ' e.g. validate and submit $newentity
  ' MsgBox "This function is not supported by the client."
  End If

End Function
Function Defect_RecordScriptSave(param)
  ' param As Variant
  ' record type name is Defect
    REM add your hook code here
  Dim error_summary
  Dim error_details
  error_summary="Submit record has been saved."
  error_details="The submit record information is:" & param
  call DieWithCustomMessage("INFO",error_summary, error_details)

End Function
Function Defect_RecordScriptCancel(param)
  ' param As Variant
  ' record type name is Defect
    REM add your hook code here
  Dim error_summary
  Dim error_details

  error_summary="CancelBackSaveHook"
  error_details="No params!"
  call DieWithCustomMessage("INFO",error_summary, error_details)

End Function

フィードバック