Extending the MyBenefits Fiori
App to hide Unenrolled Benefits
SAPUI5 Version: 1.28.31
Core Version: 1.28.30
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Web IDEVersion: 160630
Gateway application Version: 1.8.7, build number 52
Web IDE Template Version: 1.4.0
Note: If uploading to the Gateway, please refer to the following SCN document:
http://scn.sap.com/docs/DOC-74098
- 1) Open webIDE, then select New extension project:
![SCN MyBenefits 1.png]()
- 2) Select SAP HANA Cloud Platform:
![SCN MyBenefits 2.png]()
- 3) Select hcmmybenefits, then the ok button:
![SCN MyBenefits 3.png]()
- 4) Click Next, then Finish:
![SCN MyBenefits 4a.png]()
![SCN MyBenefits 4b.png]()
- 5) You are now presented with a mock up of the original MyBenefits App. Scroll to the bottom of the summary pane, click on Unenrolled, and then one of the benefit plans listed. The entire unenrolled section is the section on the summary pane we want to hide.
![SCN MyBenefits 5.png]()
- 6) The unenrolled section is created in the S2 Controller. Click on the S2 Controller in the right hand Outline window, click on Extend, and then click on “Extend with copy of original controller”:
![SCN MyBenefits 6.png]()
- 7) You will be prompted with a popup to Open Extension Code:
![SCN MyBenefits 7.png]()
- 8) We are presented with the S2 Controller’s source code with all of its functions commented out. We will only uncomment functions that we need to modify to limit the number of customized functions in the controller. Those that are commented out will automatically run the functions in the standard (original) S2 Controller.
Scroll down to function “chooseView” and uncomment the entire function. Lines 241-268:![SCN MyBenefits 8.png]()
- 9) Comment out lines 264 and 265, with appropriate comments:
![SCN MyBenefits 9.png]()
- 10) Next scroll down to function ”handleSort” and uncomment, lines 336- 408:
![SCN MyBenefits 10.png]()
- 11) Add the following line after line 377:
![SCN MyBenefits 11.png]()
- 12) Then a closing bracket after line 409:
![SCN MyBenefits 12.png]()
- 13) Scroll down to function ”getGroupHeader” and uncomment, lines 437-466:
![SCN MyBenefits 13.png]()
- 14) Comment out lines 461-463:
![SCN MyBenefits 14.png]()
- 15) Finally, go to File menu and Save, then go to the Tools menu and select Extensibility Pane. Scroll down to the bottom of MyBenefits Summary Pane, and Unenrolled plans are no longer displayed.
![SCN MyBenefits 15.png]()
Please note that that the one downside to this approach is that when there is and SAP enhancement or upgrade to MyBenefits, the functions within the S2 controller that we have just modified will need to be checked for enhancements. If so, we will need to reapply the changes above to the original SAP S2 controller supplied with the enhancement.
Here is a listing of the resulting S2 Controller extended code:
jQuery.sap.require("hcm.mybenefits.util.DataManager");
jQuery.sap.require("hcm.mybenefits.util.Formatter");
jQuery.sap.require("hcm.mybenefits.util.ConcurrentEmployment");
jQuery.sap.require("sap.ca.scfld.md.controller.ScfldMasterController");
sap.ui.controller("hcm.mybenefits.hcmmybenefitsExtension.view.S2Custom", {
// onInit: function () {
// sap.ca.scfld.md.controller.ScfldMasterController.prototype.onInit.call(this);
// this.resourceBundle = this.oApplicationFacade.getResourceBundle();
// this.oDataModel = this.oApplicationFacade.getODataModel();
// this.oApplication = this.oApplicationFacade.oApplicationImplementation;
// hcm.mybenefits.util.DataManager.init(this.oDataModel, this.resourceBundle);
// this.oRouter.attachRouteMatched(this._handleRouteMatched, this);
// this.masterListCntrl = this.byId("list");
// this.objBenfitsCollection = null;
// this._fnRefreshCompleted = null;
// this.dateChangeFlag = false;
// hcm.mybenefits.util.DataManager.setCachedModelObjProp("benefitsPlan", {});
// this.byId("S2DatePicker").setDateValue(new Date());
// this._isLocalRouting = false;
// this._isInitialized = false;
// this.searchflag = false;
// this.flag = true;
// this.refreshFlag = false;
// },
// setLeadSelection: function () {
// var i = this.masterListCntrl.getItems();
// if (i.length <= 2 && this.flag !== false) {
// if (!sap.ui.Device.system.phone) {
// this.oRouter.navTo("noData", {
// viewTitle: "MB_APP_DETAIL_TITLE",
// languageKey: sap.ui.getCore().getConfiguration().getLanguage()
// }, !sap.ui.Device.system.phone);
// }
// this.setBtnEnabled("viewSummaryID", false);
// } else {
// var f = this._oApplicationImplementation.getFirstListItem(this);
// if (f) {
// var a = f.getAttributes()[0].getText();
// if (a !== this.resourceBundle.getText("MB_SHOW_DETAILS")) {
// this.setListItem(f);
// }
// }
// }
// },
// _handleRouteMatched: function (e) {
// if (e.getParameter("name") === "master" && this._isLocalRouting === false) {
// if (!this.oApplication.pernr) {
// hcm.mybenefits.utils.ConcurrentEmployment.getCEEnablement(this, jQuery.proxy(function () {
// this._initData();
// }, this));
// }
// }
// if (e.getParameter("name") === "master" && this._isLocalRouting === true) {
// this._isLocalRouting = false;
// }
// },
// _initData: function () {
// var _ = this;
// hcm.mybenefits.util.DataManager.init(this.oDataModel, this.resourceBundle);
// if (!this.dateChangeFlag) {
// var d = new Date();
// var a = ("0" + d.getDate()).slice(-2).toString();
// var m = ("0" + (d.getMonth() + 1)).slice(-2).toString();
// var y = d.getFullYear();
// this.todayDate = a + "-" + m + ", " + y;
// this.date = d;
// this.filterDate = a + m + y;
// }
// this.filter = ["$filter=AsOn eq '" + this.filterDate + "' and EmployeeNo eq '" + this.oApplication.pernr + "' and Type eq 'Enrolled'"];
// hcm.mybenefits.util.DataManager.getMasterList(this.refreshFlag, this.dateChangeFlag, this.filter, function (o) {
// var t = _.refreshFlag;
// _.objBenfitsCollection = { "Benefits": o };
// hcm.mybenefits.util.DataManager.setCachedModelObjProp("benefitsPlan", _.objBenfitsCollection);
// try {
// if (_.objBenfitsCollection) {
// _.masterListCntrl.setModel(new sap.ui.model.json.JSONModel(_.objBenfitsCollection));
// _._isLocalRouting = true;
// this.oSorter = new sap.ui.model.Sorter("StatusCode", false, function (C) {
// var s = C.getProperty("StatusCode").trim();
// return s;
// });
// if (_.masterListCntrl.getItems().length > 0) {
// _.masterListCntrl.removeAllItems();
// }
// _.masterListCntrl.bindItems({
// path: "/Benefits",
// template: new sap.m.ObjectListItem({
// type: "{device/listItemType}",
// title: "{PlanTypeText}",
// attributes: [
// new sap.m.ObjectAttribute({ text: "{PlanSubTypeText}" }),
// new sap.m.ObjectAttribute({ text: "{PlanOptionText}" })
// ],
// firstStatus: new sap.m.ObjectStatus({
// text: "{StatusText}",
// state: "Error"
// }),
// press: jQuery.proxy(_._handleItemPress, _)
// }),
// sorter: this.oSorter
// });
// var I = 0;
// jQuery.each(_.masterListCntrl.getItems(), function (i, l) {
// if (!l.getBindingContext()) {
// _.masterListCntrl.removeItem(i - I);
// I = I + 1;
// }
// });
// if (o.length >= 0 || t) {
// var L = new sap.m.ObjectListItem({
// type: "{device/listItemType}",
// title: "",
// attributes: [
// new sap.m.ObjectAttribute({ text: _.resourceBundle.getText("MB_SHOW_DETAILS") }),
// new sap.m.ObjectAttribute({ text: "" })
// ],
// firstStatus: new sap.m.ObjectStatus({
// text: "{StatusText}",
// state: "Error"
// })
// });
// _.masterListCntrl.addItem(L);
// }
// _.originalaItems = _.masterListCntrl.getItems();
// _.handleSort();
// _._bIsMasterRoute = true;
// _.refreshHeaderFooterForEditToggle();
// if (_.originalaItems.length <= 2) {
// _.setBtnEnabled("viewSummaryID", false);
// }
// var b = _.filterDate;
// var f = b.substr(2, 2) + "/" + b.substr(0, 2) + "/" + b.substr(4, 4);
// _.byId("S2DatePicker").setDateValue(new Date(f));
// if (_._fnRefreshCompleted) {
// _._fnRefreshCompleted();
// }
// }
// } catch (e) {
// jQuery.sap.log.warning(e);
// }
// if (!sap.ui.Device.system.phone && !_._isInitialized) {
// _.registerMasterListBind(_.masterListCntrl);
// _._isInitialized = true;
// }
// if (!sap.ui.Device.system.phone) {
// if (t) {
// for (var i = 0; i < _.masterListCntrl.getItems().length; i++) {
// var c = _.masterListCntrl.getItems()[i];
// if (c.getBindingContext()) {
// var g = c.getBindingContext();
// var k = g.getProperty("PlanCategory");
// var h = g.getProperty("PlanTypeKey");
// var j = g.getProperty("PlanSubTypeKey");
// if (k === _.selectedItemKey1 && h === _.selectedItemKey2 && j === _.selectedItemKey3) {
// _.setListItem(_.masterListCntrl.getItems()[i]);
// break;
// }
// }
// }
// if (i === _.masterListCntrl.getItems().length) {
// _.setLeadSelection();
// }
// _.refreshFlag = false;
// } else {
// _.setLeadSelection();
// }
// }
// }, function (o) {
// hcm.mybenefits.util.DataManager.parseErrorMessages(o);
// });
// },
// setListItem: function
{
// var s = i.getAttributes()[0].getText();
// if (s === this.resourceBundle.getText("MB_SHOW_DETAILS")) {
// i.setVisible(false);
// this.flag = false;
// this.originalaItems = this.masterListCntrl.getItems();
// if (this.originalaItems.length < 2) {
// this.setBtnEnabled("viewSummaryID", false);
// }
// this.filter = ["$filter=AsOn eq '" + this.filterDate + "' and EmployeeNo eq '" + this.oApplication.pernr + "' and Type eq 'Unenrolled'"];
// this.fetchUnEnrolled(this.filter);
// }
// if (undefined !== i.getBindingContext()) {
// var b = i.getBindingContext();
// var p = b.getProperty("PlanCategory");
// var a = b.getProperty("Type");
// var v = this._chooseView(p, a);
// i.setSelected(true);
// this.getList().setSelectedItem(i, true);
// this.oRouter.navTo(v, { contextPath: encodeURIComponent(b.sPath.substr(1)) }, !sap.ui.Device.system.phone);
// }
// this._isLocalRouting = true;
// if (sap.ui.Device.system.phone) {
// this.masterListCntrl.removeSelections();
// }
// },
// fetchUnEnrolled: function (f) {
// var _ = this;
// hcm.mybenefits.util.DataManager.getbothMasterList(f, function (o) {
// _.objBenfitsCollection = o;
// try {
// if (_.objBenfitsCollection) {
// _.masterListCntrl.setModel(new sap.ui.model.json.JSONModel(_.objBenfitsCollection));
// var I = 0;
// jQuery.each(_.masterListCntrl.getItems(), function (i, a) {
// if (!a.getBindingContext()) {
// _.masterListCntrl.removeItem(i - I);
// I = I + 1;
// }
// if (I === 0) {
// this.ifenrld = false;
// }
// });
// _.mcount = 0;
// var b = _.masterListCntrl.getItems().length;
// var d = _.originalaItems.length;
// _.originalaItems = _.masterListCntrl.getItems();
// _.handleSort();
// _._bIsMasterRoute = true;
// var y = _.filterDate;
// _.refreshHeaderFooterForEditToggle();
// if (_.originalaItems.length < 2 || d === 2) {
// _.setBtnEnabled("viewSummaryID", false);
// }
// _.masterListCntrl.getInfoToolbar().getContent()[1].setValue(y.substr(0, 2) + "-" + y.substr(2, 2) + "-" + y.substr(4, 4));
// if (_._fnRefreshCompleted) {
// _._fnRefreshCompleted();
// }
// }
// if (!sap.ui.Device.system.phone) {
// _.setLeadSelection();
// }
// } catch (e) {
// jQuery.sap.log.warning(e);
// }
// }, function (o) {
// hcm.mybenefits.util.DataManager.parseErrorMessages(o);
// });
// },
_chooseView: function (p, a) {
var v = "";
if (a == "Enrolled" || a == "Pending") {
switch (p) {
case "A":
v = "Health";
break;
case "B":
v = "Insurance";
break;
case "C":
v = "Savings";
break;
case "D":
v = "FSA";
break;
case "E":
v = "Miscellaneous";
break;
case "F":
v = "Savings";
break;
}
// dkumm - 6/20/2016 - begin suppression of unenrolled benefits section.
// } else if (a == "Unenrolled") {
// v = "Unenrolled";
// dkumm - 6/20/2016 - end suppression of unenrolled benefits section.
}
return v;
},
// applySearchPatternToListItem: function (i, f) {
// if (undefined !== i.getBindingContext())
// if (f.substring(0, 1) === "#") {
// var t = f.substr(1), d = i.getBindingContext().getProperty("Name").toLowerCase();
// return d.indexOf(t) === 0;
// } else {
// if (f === "") {
// return true;
// }
// var I = i.getBindingContext();
// if (I.getProperty("PlanTypeText").toLowerCase().indexOf(f) !== -1 || I.getProperty("PlanSubTypeText").toLowerCase().indexOf(f) !== -1 || I.getProperty("PlanOptionText").toLowerCase().indexOf(f) !== -1) {
// return true;
// }
// return false;
// }
// },
// applySearchPattern: function (f) {
// var l = this.originalaItems, m = [], v, f = f.toLowerCase(), c = 0;
// this.searchflag = true;
// if (f !== "") {
// for (var i = 0; i < l.length; i++) {
// v = this.applySearchPatternToListItem(l[i], f);
// if (v) {
// m.push(l[i]);
// c++;
// }
// }
// } else {
// m = this.originalaItems;
// c = this.originalaItems.length;
// }
// if (m.length > 0) {
// this.handleSort(m);
// }
// this.masterListCntrl.removeSelections();
// if (this._fnRefreshCompleted) {
// this._fnRefreshCompleted();
// sap.ca.ui.utils.busydialog.releaseBusyDialog();
// }
// return c;
// },
// handleChange: function (e) {
// var D = e.getParameters().newValue;
// var v = D.split("-"), y = v[2], a = v[1], b = v[0], _ = this;
// D = b + a + y;
// if (Number(D).toString() === "NaN") {
// var d = new Date();
// var c = ("0" + d.getDate()).slice(-2).toString();
// var f = ("0" + (d.getMonth() + 1)).slice(-2).toString();
// var g = d.getFullYear();
// D = c + f + g;
// }
// _.filterDate = D;
// _.tempDate = D;
// _.dateChangeFlag = true;
// _.flag = true;
// if (_._oControlStore.oMasterSearchField.getValue()) {
// _._oControlStore.oMasterSearchField.clear();
// }
// var m = new sap.ui.core.routing.HashChanger();
// var u = m.getHash();
// m.setHash(u);
// _._initData();
// _.dateChangeFlag = true;
// },
handleSort: function (m) {
var s = this, I = 0, l = this.byId("list"), S = "StatusCode", g = true;
jQuery.each(l.getItems(), function (i, a) {
if (!a.getBindingContext()) {
l.removeItem(i - I);
I = I + 1;
}
});
var c = l.getItems();
if (undefined !== m && m !== null) {
c = m;
} else {
c = this.originalaItems;
}
c.sort(function (a, b) {
if (a.getBindingContext()) {
var v = a.getBindingContext().getProperty(S);
} else {
v = null;
}
if (b.getBindingContext()) {
var f = b.getBindingContext().getProperty(S);
} else {
f = null;
}
return s.compareFunction(v, f);
});
l.removeAllItems();
var d = 0;
var G = 0;
var o, e;
jQuery.each(c, function (i, a) {
if (a.getBindingContext()) {
var C = a.getBindingContext().getProperty("StatusCode");
} else if (a.getAttributes()[0].getText()) {
if (a.getAttributes()[0].getText() === s.resourceBundle.getText("MB_SHOW_DETAILS")) {
C = "2U";
}
}
if (C === "") {
C = "UnGrouped";
}
// dkumm - 6/20/2016 - begin suppression of unenrolled benefits section.
if (C !== "2U") {
// dkumm - 6/20/2016 - end suppression of unenrolled benefits section.
if (g && (i === 0 || C !== e)) {
if (i !== 0) {
o.setCount(G);
}
e = C;
o = new sap.m.GroupHeaderListItem({ title: s.getGroupHeader(C) });
l.insertItem(o, i + d);
d = d + 1;
G = 0;
} else if (g && (i + 1 === c.length || i + 1 === c.length && i === 0)) {
G = G + 1;
o.setCount(G);
if (o.getTitle() !== s.resourceBundle.getText("MB_LIST_HEADER_UNENROLLED") && s.mcount === 0) {
sap.m.MessageToast.show(s.resourceBundle.getText("MB_NO_UNENROLLED_PLAN"), { width: "15em" });
s.mcount = 1;
}
}
if (!s.flag && i + 1 === c.length) {
if (o.getCount() === "") {
G = G + 1;
}
if (o.getTitle() !== s.resourceBundle.getText("MB_LIST_HEADER_UNENROLLED") && s.mcount === 0) {
sap.m.MessageToast.show(s.resourceBundle.getText("MB_NO_UNENROLLED_PLAN"), { width: "15em" });
s.mcount = 1;
}
o.setCount(G);
}
G = G + 1;
l.addItem(a);
// dkumm - 6/20/2016 - begin suppression of unenrolled benefits section.
}
// dkumm - 6/20/2016 - end suppression of unenrolled benefits section.
});
},
// compareFunction: function (a, b) {
// try {
// if (b === null) {
// return -1;
// }
// if (a === null) {
// return 1;
// }
// if (typeof a === "string" && typeof b === "string") {
// return a.toLocaleUpperCase().localeCompare(b.toLocaleUpperCase());
// }
// if (a < b) {
// return -1;
// }
// if (a > b) {
// return 1;
// }
// return 0;
// } catch (e) {
// jQuery.sap.log.error("failed to compare:" + a + " and " + b, ["failed in compareFunction S2 controller"], ["hcm.mybenefits.view.S2.controller"]);
// }
// },
getGroupHeader: function (g) {
var r = "";
switch (g) {
case "0P":
r = this.resourceBundle.getText("MB_LIST_HEADER_PENDING");
break;
case "1A":
r = this.resourceBundle.getText("MB_LIST_HEADER_HEALTH");
break;
case "1B":
r = this.resourceBundle.getText("MB_LIST_HEADER_INSURANCE");
break;
case "1C":
r = this.resourceBundle.getText("MB_LIST_HEADER_SAVINGS");
break;
case "1D":
r = this.resourceBundle.getText("MB_LIST_HEADER_FSA");
break;
case "1E":
r = this.resourceBundle.getText("MB_LIST_HEADER_MISC");
break;
case "1F":
r = this.resourceBundle.getText("MB_LIST_HEADER_STOCK");
break;
// dkumm - 6/20/2016 - begin suppression of unenrolled benefits section.
// case "2U":
// r = this.resourceBundle.getText("MB_LIST_HEADER_UNENROLLED");
// break;
// dkumm - 6/20/2016 - end suppression of unenrolled benefits section.
}
return r;
},
// getViewSummary: function () {
// var v = this.getView(), d = v.byId("list").getInfoToolbar().getContent()[1].getValue(), a = d.split("-"), y = a[2], m = a[1], b = a[0], d = b + m + y;
// var p = this.oApplicationFacade.oApplicationImplementation.oConfiguration.getServiceList()[0].serviceUrl + "FileDataSet(FileKey='CONF_FORM',Date='" + d + "',EmployeeNo='" + this.oApplication.pernr + "')/$value", q = "?", c = "&", s = "";
// if (location.host.indexOf("localhost") !== -1) {
// s = "sap-server=gm6-http" + c;
// }
// p += q + s;
// sap.m.URLHelper.redirect(p, true);
// },
// getHeaderFooterOptions: function () {
// var l = this.byId("list");
// var c = l.getItems().length;
// jQuery.each(l.getItems(), function (i, I) {
// if (!I.getBindingContext()) {
// c--;
// }
// });
// return {
// sI18NMasterTitle: this.resourceBundle.getText("MB_MASTER_TITLE", [c]),
// buttonList: [{
// sId: "viewSummaryID",
// bDisabled: false,
// sI18nBtnTxt: this.resourceBundle.getText("MB_CONFIRMATION"),
// onBtnPressed: jQuery.proxy(function (e) {
// this.getViewSummary(e);
// }, this)
// }],
// onRefresh: jQuery.proxy(function (s, r) {
// this.refreshFlag = true;
// this.flag = true;
// this._fnRefreshCompleted = r;
// var m = new sap.ui.core.routing.HashChanger();
// var u = m.getHash().split("&")[0];
// m.setHash(u);
// hcm.mybenefits.util.DataManager.setCachedModelObjProp("benefitsPlan", {});
// if (this.masterListCntrl.getSelectedItem()) {
// var a = this.masterListCntrl.getSelectedItem().getBindingContext();
// this.selectedItemKey1 = a.getProperty("PlanCategory");
// this.selectedItemKey2 = a.getProperty("PlanTypeKey");
// this.selectedItemKey3 = a.getProperty("PlanSubTypeKey");
// }
// if (s) {
// this._oControlStore.oMasterSearchField.clear();
// }
// this._initData();
// this.dateChangeFlag = true;
// }, this)
// };
// }
});