What Is Business Rules Capability?
The business rules capability within the SAP Workflow Management service lets you digitize and automate decision making. It encapsulates dynamic decision logic from application logic. It also provides web-based tools to model business vocabulary and decision interfaces to integrate with SaaS applications and business services.
Business rules let you automate the decision-making process for a business scenario. For example, in an employee onboarding scenario, you can model business rules for the HR team to automate the equipment determination step for a new hire. Depending on the employee’s designation, the required equipment can be automatically determined without the intervention of the HR team.
Note: this is just a sample implementation with sample data. You may wanted to customise this to your organization specific needs.
In my explanation, I will be using screenshots to denote each step I followed, Kindly get familiarise yourself designing Business Rules. In case you are new to this topic, I encourage you to explore our tutorials on this topic.
Business Rule Project Creation - Project Details
Business Rule Design
ProcessRegion
processDepartment
A ruleset is a logical collection of rules that helps you group business logic that govern a specific function.
<Label text="{i18n>USER_ID}" required="true"/>
<Input id="requesterUserId" value="{mCommon>/oRequesterDetails/sRequesterUserId}" placeholder="P000123" valueState="{mCommon>/sRequesterUserIdState}"
valueStateText="{mCommon>/sRequesterUserIdStateText}" change="onChange" enabled="{mCommon>/oEnable/sInput}"/>
<!-- Add Region -->
<Label text="{i18n>REGION}" required="true"/>
<Input id="requesterRegion" value="{mCommon>/oRequesterDetails/sRequesterRegion}" placeholder="APJ" valueState="{mCommon>/sRequesterRegionState}"
valueStateText="{mCommon>/sRequesterRegionStateText}" change="onChange" enabled="{mCommon>/oEnable/sInput}"/>
<!-- Add Department -->
<Label text="{i18n>DEPARTMENT}" required="true"/>
<Input id="requesterDepartment" value="{mCommon>/oRequesterDetails/sRequesterDepartment}" placeholder="PCH" valueState="{mCommon>/sRequesterDepartmentState}"
valueStateText="{mCommon>/sRequesterDepartmentStateText}" change="onChange" enabled="{mCommon>/oEnable/sInput}"/>
<Label text="{i18n>COMMENT_FROM_REQUESTER}" required="false"/>
<TextArea id="requesterComment" rows="5" value="{mCommon>/oRequesterDetails/sRequesterComment}" enabled="{mCommon>/oEnable/sInput}"/>
#XFLD:
USER_ID=User ID
#XFLD:
REGION=Region
#XFLD:
DEPARTMENT=Department
...
...
...
#XMSG:
FIELD_VALIDATION_ERROR_TITLE = Title is a required field(*)
#XMSG:
FIELD_VALIDATION_ERROR_USER_REGION_OR_DEPARTMENT = You need to enter Region or Department
onPressRequestApproval: function (oEvent) {
var errorExist = false,
oThisController = this,
oMdlCommon = oThisController.getParentModel("mCommon");
oThisController.getView().setBusy(true);
// Checking Requester Fields
var requesterFields = [
"sRequesterFirstName",
"sRequesterLastName",
"sRequesterEmail",
"sRequesterUserId",
// modified code -- Start
"sRequesterRegion",
"sRequesterDepartment"
// modified code -- end
];
var requesterValue;
for (var i = 0; i < requesterFields.length; i++) {
requesterValue = oMdlCommon.getProperty("/" + "oRequesterDetails" + "/" + requesterFields[i]);
if (requesterValue && requesterValue.trim() && requesterValue !== "" && requesterValue !== "undefined" && requesterValue !==
"null") {
oMdlCommon.setProperty("/" + requesterFields[i] + "State", "None");
} else {
errorExist = true;
if (requesterFields[i] === "sRequesterFirstName") {
oMdlCommon.setProperty("/" + requesterFields[i] + "StateText", oThisController.getMessage("FIELD_VALIDATION_ERROR_FIRST_NAME"));
}
if (requesterFields[i] === "sRequesterLastName") {
oMdlCommon.setProperty("/" + requesterFields[i] + "StateText", oThisController.getMessage("FIELD_VALIDATION_ERROR_LAST_NAME"));
}
if (requesterFields[i] === "sRequesterEmail") {
oMdlCommon.setProperty("/" + requesterFields[i] + "StateText", oThisController.getMessage("FIELD_VALIDATION_ERROR_EMAIL"));
}
if (requesterFields[i] === "sRequesterUserId") {
oMdlCommon.setProperty("/" + requesterFields[i] + "StateText", oThisController.getMessage("FIELD_VALIDATION_ERROR_USER_ID"));
}
// modified code -- Start
if (requesterFields[i] === "sRequesterRegion") {
bRegionOrDepartmentIsEmpty = true;
}
if (requesterFields[i] === "sRequesterDepartment" && bRegionOrDepartmentIsEmpty) {
oMdlCommon.setProperty("/" + requesterFields[i] + "StateText", oThisController.getMessage("FIELD_VALIDATION_ERROR_USER_DEPARTMENT"));
}
// modified code -- end
oMdlCommon.setProperty("/" + requesterFields[i] + "State", "Error");
}
}
...
// more code
...
startInstance: function (workflowtoken) {
...
// code
...
var sPayload = {
"definitionId": sDefinitionId,
"context": {
"RequestId": oMdlCommon.getProperty("/sRequestId").toString(),
"Title": oMdlCommon.getProperty("/sTitle"),
"Requester": {
"FirstName": oMdlCommon.getProperty("/oRequesterDetails/sRequesterFirstName"),
"LastName": oMdlCommon.getProperty("/oRequesterDetails/sRequesterLastName"),
"Email": oMdlCommon.getProperty("/oRequesterDetails/sRequesterEmail"),
"UserId": oMdlCommon.getProperty("/oRequesterDetails/sRequesterUserId"),
// change start
"Region": oMdlCommon.getProperty("/oRequesterDetails/sRequesterRegion"),
"Department": oMdlCommon.getProperty("/oRequesterDetails/sRequesterDepartment"),
// change end
"Comments": oMdlCommon.getProperty("/oRequesterDetails/sRequesterComment")
},
"ApprovalSteps": aApprovalSteps,
"Attachments": aAttachments
}
};
...
// code
...
}
_getApproverGroup : function() {
var oThisController = this;
var oMdlCommon = this.getParentModel("mCommon");
var sRequesterRegion = oMdlCommon.getProperty("/oRequesterDetails/sRequesterRegion");
var sRequesterDepartment = oMdlCommon.getProperty("/oRequesterDetails/sRequesterDepartment");
var sInputAttribute = "";
if(sRequesterRegion !== "" && sRequesterRegion !== undefined && sRequesterRegion!==
"null"){
sInputAttribute += '"Region": "' + sRequesterRegion + '"';
}else if(sRequesterDepartment !== "" && sRequesterDepartment !== undefined && sRequesterDepartment!==
"null"){
sInputAttribute += '"Department": "' + sRequesterDepartment + '"';
}else{
var noInput = oThisController.getMessage("FIELD_VALIDATION_ERROR_USER_REGION_OR_DEPARTMENT")
oMdlCommon.setProperty("/sRequesterRegionState", "Error");
oMdlCommon.setProperty("/sRequesterRegionStateText", noInput);
oMdlCommon.setProperty("/sRequesterDepartmentState", "Error");
oMdlCommon.setProperty("/sRequesterDepartmentStateText", noInput);
var sGenericErrorText = oThisController.getMessage("FIELD_VALIDATION_ERROR_GENERIC");
MessageToast.show(sGenericErrorText)
oThisController.getView().setBusy(false);
return true;
}
var sUrl = this._getBusinessRulesRuntimeBaseURL()+ '/rule-services';
var jsonData = "{" +
'"RuleServiceId": "c4a96475ddc2445294698234bbf609ad",' +
'"RuleServiceRevision": "initial",'+
'"Vocabulary": ['+
'{' +
'"inputAttributes": {'+sInputAttribute+
'}' +
'}' +
']' +
'}';
var oSettings = {
"url": sUrl,
"method": "POST",
"async": false,
"headers": {
"Content-Type": "application/json",
"Accept": "application/json",
},
"data" : jsonData
};
$.ajax(oSettings)
.done(function (results, textStatus, request) {
console.log("execution successfull");
var oMdlCommon = oThisController.getParentModel("mCommon");
oMdlCommon.setProperty("/sApproverGroup",results.Result[0].approverGroup);
oMdlCommon.refresh();
})
.fail(function (err) {
console.log("execution failed");
});
return false;
}
getUsers: function (oColumns, sInputField) {
var oThisController = this;
this._getApproverGroup();
var oMdlCommon = this.getParentModel("mCommon");
var oView = oThisController.getView();
oView.setBusy(true);
var scimbaseurl = this._getSCIMBaseURL();
var sRole = oMdlCommon.getProperty("/sApproverGroup");
var sFilter = 'filter=groups.display eq "' + sRole + '"';
var sUrl = this._getSCIMBaseURL() + '/service/scim/Users?'+ encodeURIComponent(sFilter);
var oSettings = {
"url": sUrl,
"method": "GET"
};
...
// more code
...
}
getUsersAdd: function (iteration, oColumns, sInputField) {
var oThisController = this;
var oView = oThisController.getView();
oView.setBusy(true);
var startIndex = (100 * iteration) + 1;
var scimbaseurl = this._getSCIMBaseURL();
var sRole = oMdlCommon.getProperty("/sApproverGroup");
var sFilter = 'filter=groups.display eq "' + sRole + '"';
var sUrl = scimbaseurl+ '/service/scim/Users?startIndex=' + startIndex + '&' + encodeURIComponent(sFilter);
var oSettings = {
"url": sUrl,
"method": "GET",
"async": false
};
...
// more code
...
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
25 | |
17 | |
13 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 |