在腳本中使用商務邏輯限定存取

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

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

檢查具有相關聯商務規則之工作所包含的作業存取權時,應用程式必須建立兩個大小相同的陣列,以作為IAzClientCoNtext物件的AccessCheck方法的 varParameterNamesvarParameterValues參數傳遞。 如需建立用戶端內容的相關資訊,請參閱 在腳本中建立用戶端內容

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)
 
%>