Add the following custom method to the Rules Business Call - Task Opportunity business service:
function Rules(Inputs:PropertySet, Outputs:PropertySet)
{
try
{
//Declare a business service variable.
var svc:Service = TheApplication().GetService("Business Rule Service");
//Declare the inputs property set variable for Business Rule Service. Declare
//child and grandchild property sets that build the
//hierarchical structure of the BusCompList input property.
var inputs:PropertySet = TheApplication().NewPropertySet();
var child:PropertySet = TheApplication().NewPropertySet();
var grandchild:PropertySet = TheApplication().NewPropertySet();
//Declare the outputs property set variable for Business Rule Service.
var outputs:PropertySet = TheApplication().NewPropertySet();
//Declare the variable that gets the row id of the new lead from the task.
var RowIdInput:chars = Inputs.GetProperty("vRowId");
//Declare variables to store results.
var valResult:chars;
var TheResult:chars;
//Use methods to build input property set structure.
//Setting RuleModuleName to module you wish to call.
inputs.SetProperty("RuleModuleName", "New Lead");
//Setting PerformAction to "Y" because our rule statements include
//setfieldvalue calls to process.
inputs.SetProperty("PerformAction", "Y");
//Setting GetMoreData to "Y" because you want the rules engine to get all
//the child business components and fields automatically, instead of passing
//them all explicitly.
inputs.SetProperty("GetMoreData", "Y");
//Build the BusCompList > BusComp > Field hierarchy.
child.SetType("BusCompList");
grandchild.SetType("BusComp");
grandchild.SetProperty("Id", RowIdInput);
grandchild.SetProperty("Name", "Opportunity");
child.AddChild(grandchild);
inputs.AddChild(child);
// Invoke Business Rule Service.
svc.InvokeMethod("RunRules", inputs, outputs);
// Examine the outputs property set.
var nChild = outputs.GetChildCount();
var i = 0;
var resultType;
var errorText;
// If no result, then the derivation passed in this example.
if (nChild == 0)
{
return (ContinueOperation);
}
// In this example, you only look for RaiseErrorText and DerivationList
// because you only used those actions in the New Lead rule module.
for (i = 0; i < nChild; i++)
{
resultType = outputs.GetChild(i).GetType();
//Process RaiseErrorText result
if (resultType == "RaiseErrorText")
{
errorText = outputs.GetChild(i).GetValue();
return(CancelOperation);
}
// Process DerivationList result.
if (resultType == "DerivationList")
{
var j = 0;
var msg:PropertySet = TheApplication().NewPropertySet();
var valList:PropertySet = outputs.GetChild(i);
var valCount:float = valList.GetChildCount();
// Look at each Derivation result.
for (j = 0; j < valCount; j++)
{
valResult = valList.GetChild(j).GetProperty("Result");
if (valResult != "Valid")
{
var val:PropertySet = valList.GetChild(j);
var msgCount = val.GetChildCount();
var k = 0;
for (k = 0; k < msgCount; k++)
{
TheResult = val.GetChild(k).GetValue();
}
return (TheResult);
}
}
}
}
}//end try
catch(e)
{
TheApplication().RaiseErrorText("Error in the Rules function: " + e.toString());
}
finally
{
}
}
For information and examples of the output property sets, see Output Property Set Schema for Business Rule Service.