Guidelines for creating event rules
You can use the following guidelines and references for using API to create event rules:
- Refer to the BMC IT Business Management Suite Javadoc to gather information about the APIs available for writing the event rules.
- Use java documentation in all APIs in ITBMApiServicesBean. You can access the ITBMApiServicesBean as a JavaScript variable called API in the event rules.
For example, to invoke a method called getMetaData(“Project”), you specify API.getMetaData(“Project”). You do not need to create an instance of the API Session bean.
The JavaScript variable, API, has all the CRUD operations available given a DTOBase (DataTransferObject). All data objects in BMC IT Business Management Suite extend from DTOBase. - Get metadata information about the object that you need to create. To get metadata information, use API.getMetaData(“ObjectType”). This returns an instance of ItmEJBMetaData object. The object has APIs such as getAllFields () and getAllRelationFields (). These APIs return an instance of AttributeMetaData that has all the information about a specific field.
- Refer to ObjectTypeLiterals Java Doc to get a list of object types.
- Use APIs such as API.logDebug() and API.logError to log messages in event rules.
- Use API.sendAlert(…) methods to send Alert messages.
- Use getEJBServices and getEJBFactory to get Services Bean for an object (used for crud operations) or Factory Bean (used for read operations) respectively.
Debugging event rule scripts
You can use one of the following processes to debug an event rule script:
- Use the System.out.println() call to print debug information on system console.
- Use the published API calls to generate debug information in a log file.
Sample event rule
The sample script creates corporate mandatory 10 budget line items and 5 actual line items, when a user creates a project. The script uses the Test Alerts workflow. The script creates each line item with a cost of $1000. The script also sends a notification alert or email to the project managers, after line items are created.
importPackage(Packages.com.itmsoft.common);
importPackage(Packages.com.itmsoft.common.authorization);
importPackage(Packages.com.itmsoft.common.dto);
importPackage(Packages.com.itmsoft.common.scripting);
importPackage(Packages.com.itmsoft.common.text);
importPackage(Packages.java.math);
importPackage(Packages.java.util);
importPackage(Packages.com.itmsoft.common.financial);
//check if workflow name is "Test Alerts", and add to project
//10 budget line items and 5 actual line items with 1000$ cost in it
wfLabelDTO = dto.getWorkflow();
if (wfLabelDTO.getLabel() == "Test Alerts")
{
//get budget complete dto from budget project task complete dto
bptCompleteDTO = API.findDefaultByProjectBudgetProjectTaskCompleteDTO(dto.getId());
budgetLabelDTO = bptCompleteDTO.getProjectBudget();
budgetCompleteDTO = API.getCompleteDTO(budgetLabelDTO);
vendorReview Vendor Review Notification
//get GL with sys id 1
glaLabelDTO = API.getGeneralLedgerAccountLabelDTO(new Integer(1));
//get top level business unit of the company
companyLabelDTO = dto.getDataAccessCompany();
buLabelDTO = API.findRootNodeByCompanyBusinessUnitLabelDTO(companyLabelDTO.getId());
//get default value for cost type code and line item allocation type code
costTypeCode = API.findDefaultCodeInGroupCodeTableLabelDTO("COST_TYPE_CODE");
allocTypeCode =
API.findDefaultCodeInGroupCodeTableLabelDTO("LINE_ITEM_ALLOCATION_TYPE_CODE");
//add to project, 10 budget line items with $1000 cost in it
var i = 0;
for (i = 0; i < 10; i++)
{
costs = new ArrayList();
blidCompleteDTO = new BudgetLineItemDetailCompleteDTO();
blidCompleteDTO.setQuantity(BigDecimal.valueOf(1));
blidCompleteDTO.setUnitCost(BigDecimal.valueOf(1000));
blidCompleteDTO.setDataAccessCompany(companyLabelDTO);
cost = new ITMCurrency("USD", BigDecimal.valueOf(1000), new Integer(i), new Integer(2009));
blidCompleteDTO.setCost(cost);
costs.add(blidCompleteDTO);
bliCompleteDTO = new BudgetLineItemCompleteDTO();
bliCompleteDTO.setProject(dto);
bliCompleteDTO.setBudget(budgetLabelDTO);
bliCompleteDTO.setPayerBusinessUnit(buLabelDTO);
bliCompleteDTO.setAllocationTypeCode(allocTypeCode);
bliCompleteDTO.setCostType(costTypeCode);
bliCompleteDTO.setDataAccessCompany(companyLabelDTO);
bliCompleteDTO.setGeneralLedgerAccount(glaLabelDTO);
bliCompleteDTO.setShortDescription("bli" + i);
bliCompleteDTO.setCosts(costs);
API.save(bliCompleteDTO, false);
}
//add to project, 5 actual line items with $1000 cost in it
for (i = 0; i < 5; i++)
{
cost = new ITMCurrency("USD", BigDecimal.valueOf(1000), new Integer(i), new Integer(2009));
aliCompleteDTO = new ActualLineItemCompleteDTO();
aliCompleteDTO.setProject(dto);
aliCompleteDTO.setPayerBusinessUnit(buLabelDTO);
aliCompleteDTO.setAllocationTypeCode(allocTypeCode);
aliCompleteDTO.setCostType(costTypeCode);
aliCompleteDTO.setShortDescription("ali" + i);
aliCompleteDTO.setDataAccessCompany(companyLabelDTO);
aliCompleteDTO.setGeneralLedgerAccount(glaLabelDTO);
aliCompleteDTO.setQuantity(BigDecimal.valueOf(1));
aliCompleteDTO.setUnitCost(BigDecimal.valueOf(1000));
aliCompleteDTO.setCost(cost);
API.save(aliCompleteDTO, false);
}
//create message
message = new StringBuffer();
message.append("Corporate mandatory budget and actual line items with $1000 cost in it, have
been created for the project ");
message.append("\"");
message.append("<b>");
message.append(dto.getLabel());
message.append("</b>");
message.append("\"");
//send alert
API.sendAlert(event.getEventName(), event.getEventSource(), ruleId, dto.getProjectManagers(),
"Mandatory line items created", message.toString().replaceAll("<b>", "").replaceAll("</b>", ""),
message.toString().replaceAll("\n", "<br>"));
}
Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*