Apertura di un modulo prepopolato

Gli hook globali GSU_CQXE_OpenForm e GSU_CQXE_OpenSubmitForm forniscono la possibilità di aprire moduli prepopolati dagli hook. Dopo aver aggiunto gli hook globali allo schema è possibile accedere ad essi per specificare il tipo di record del modulo ed inizializzarlo con valori campo.

Per istruzioni sul download del codice hook globale, consultare la technote 1432968 alla pagina http://www.ibm.com/support/docview.wss?&rs=939&uid=swg21432969.

Questa funzionalità è disponibile sui client ClearQuest per web e Eclipse. Se un utente tenta di aprire un modulo da un client obsoleto o da un client ClearQuest per Windows, l'API restituisce un messaggio informativo. Per visualizzare all'utente questo messaggio, richiamare la funzione die.

Se il client supporta questa funzione, l'API emette un'eccezione e il codice dopo la chiamata dell'API non verrà eseguito. Utilizzare gli hook di callback nello script per eseguire l'eventuale ulteriore codice dopo la chiamata dell'API.

Esempi

Utilizzare questi esempi di record e script azione con gli hook globali per fornire agli utenti dei moduli prepopolati. In questo esempio, l'azione CreateChildDefect apre un modulo di inoltro prepopolato con i valori dall'hook RecordScript. L'utente può annullare o salvare il modulo, ciò esegue il codice negli hook RecordScriptCancel e RecordScriptSave.

Per utilizzare questo esempio, apportare le seguenti modifiche allo schema:
  1. Aggiungere due nuovi campi al tipo di record Defect: un campo DATE_TIME denominato dateTime e un campo REFERENCE_LIST denominato children.
  2. Impostare l'attributo Riferimento a del campo children su Defect.
  3. Creare tre script record denominati RecordScript, RecordScriptSave e RecordScriptCancel, utilizzando il codice Perl o VBScript di esempio fornito di seguito.
  4. Aggiungere una nuova azione RECORD_SCRIPT_ALIAS denominata CreateChildDefect al tipo di record Defect. Impostare l'azione CreateChildDefect in modo che utilizzi l'hook RecordScript precedentemente creato.
  5. Aggiungere una nuova scheda denominata OpenForm al modulo Defect_Base nel tipo di record Defect.
  6. Sulla nuova scheda OpenForm, aggiungere i seguenti controlli:
    • Un campo testo impostato per visualizzare sia la Data sai l'Ora. Selezionare Data estesa per il formato di visualizzazione della data. Selezionare dateTime per il campo origine.
    • Un controllo Padre/Figlio con il campo origine impostato su children.
Nota: alcuni di questi esempi di codice utilizzano la funzione DieWithCustomMessage per gestire i messaggi di errore restituiti dall'API. Per ulteriori informazioni su questo script globale consultare Generazione di un messaggio di errore personalizzato.

Esempi 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;
}

Esempi 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

Feedback