VBScript を使用する場合、レコード スクリプト、フィールド フック、アクション フックは暗黙的に Entity オブジェクトと関連付けられます。別の Entity オブジェクトを特に指定しない限り、Entity クラスのメソッドのすべての呼び出しは、この暗黙オブジェクトを参照します。Perl を使用する場合は、定義済み変数 ($entity) とのこの関連付けを参照します。
次の例は、ボタン クリックとコンテキスト メニュー項目の選択の両方に対応できるレコード スクリプトを示します。ボタンがクリックされると、このフックは、コンポーネントの指導エンジニアの名前を [component_ref] フィールドに入れます。これは、障害の作業を割り当てられた担当者を表示します。
この例は、スキーマにレコード スクリプトを追加する一般的な方法を示します。この例では、 エラー チェックを組み込んでいません。検証 API の戻り値を調べて、エラーが含まれていないことを確認してから、レコードをデータベースにコミットしてください。
Function Request_AssignEngineer(param)
' param As Variant
' This hook responds to changes in the current component and
' assigns the request to the lead engineer for that component.
Dim eventType, componentObj, leadname
eventType = param.EventType
If eventType = AD_BUTTON_CLICK Then
' Get the lead person for the given component
leadName = GetFieldValue("component_lead").GetValue
If leadName = "" Then
Request_AssignEngineer = "Couldn't get Component Lead value"
Exit function
End if
' Put that person's name in the Assigned To: field
SetFieldValue "component_ref", leadName
Request_AssignEngineer = SetFieldValue "component_ref", leadName
Elseif eventType = AD_CONTEXMENU_ITEM_SELECTION Then
SetFieldValue "component_ref", GetSession.GetUserFullname
Request_AssignEngineer = SetFieldValue "component_ref", GetSession.GetUserFullname
End if
End Function