在腳本中使用商業規則限定存取

使用商務規則腳本來提供運行時間邏輯來檢查存取權。 如需商務規則的詳細資訊,請參閱 商務規則。

若要將商務規則指派給工作,首先設定 BizRuleLanguage 屬性,該屬性屬於代表此工作的 IAzTask 物件。 腳本必須使用 Visual Basic Scripting Edition (VBScript) 程式設計語言或 JScript 開發軟體撰寫。 指定文稿語言之後,請使用腳本的字串表示,設定 IAzTask 物件的 BizRule 屬性。

檢查具有相關聯商務規則之工作所包含的作業存取權時,應用程式必須建立兩個大小相同的陣列,才能與 varParameterNames 和 varParameterValuesAccessCheck 方法 IAzClientContext 物件的參數一樣傳遞。 如需建立用戶端內容的相關信息,請參閱 在腳本中建立用戶端內容。

AccessCheck 方法會建立一個 AzBizRuleContext 物件,然後將它傳遞至商務規則腳本。 然後腳本會設定 AzBizRuleContext 物件的 BusinessRuleResult 属性。 值為 True 表示授予存取權,而值為 False 表示拒絕存取。

商務規則腳本無法指派給由委派的 IAzScope 物件所包含的 IAzTask 物件。

下列範例示範如何使用商務規則腳本來檢查客戶端對作業的存取權。 此範例假設磁碟驅動器 C 根目錄中有一個名為 MyStore.xml 的現有 XML 原則存放區,而且此存放區包含名為 Expense 的應用程式、名為 Submit Expense 的工作,以及名為 UseFormControl 的作業。

<%@ Language=VBScript %>
<%
'  Create the AzAuthorizationStore object.
Dim AzManStore
Set AzManStore = CreateObject("AzRoles.AzAuthorizationStore")

'  Initialize the authorization store.
AzManStore.Initialize 0, "msxml://C:\MyStore.xml"

'  Open the application object in the store.
Dim expenseApp
Set expenseApp = AzManStore.OpenApplication("Expense")

'  Create a client context.
Dim clientName
clientName = Request.ServerVariables("LOGON_USER")
Dim clientContext
Set clientContext = _
    expenseApp.InitializeClientContextFromName(clientName)

'  Create a business rule for the Submit Expense task.

'  Open the Submit Expense task.
Dim submitTask
Set submitTask = expenseApp.OpenTask("Submit Expense")

'  Set the business rule language to VBScript.
submitTask.BizRuleLanguage = "VBScript"

'  Create a string with the business rule code.
Dim newline
newline = chr(13)
Dim bizRuleString
bizRuleString = "Dim Amount" + newline _
         +"AzBizRuleContext.BusinessRuleResult = FALSE" + newline _
         +"Amount = AzBizRuleContext.GetParameter(""ExpAmount"")" _
   +newline _
   +"if Amount < 500 then AzBizRuleContext.BusinessRuleResult = TRUE"

'  Assign the business rule to the Submit Expense task.
submitTask.BizRule = bizRuleString
                
'  Save the task information to the store.
submitTask.Submit

'  Open the operation to check.
Dim formOperation
Set formOperation = expenseApp.OpenOperation("UseFormControl")

'  Get the ID of the operation.
Dim operationID
operationID = formOperation.OperationID

'  Set up arrays for operations and results.
Dim Operations(1)
Operations(0) = operationID
Dim Results

'  Set up business rule parameters.
Dim bizNames(1)
Dim bizValues(1)
bizNames(0) = "ExpAmount"
bizValues(0) = 100

'  Check access.
Results = clientContext.AccessCheck _
    ("UseFormControl", Empty, Operations, bizNames, bizValues)
 
%>