Creating and using the custom utility methods
You can create custom utility methods and use them for custom behavior logic.
Procedure
- Create package folders in the <INSTALL_DIR>/extensions/isccs/webpages directory.
For example, for the
extn.extnUtils.MyUtil
file, createextnUtils
in the specified directory. - Create a JavaScript utility file in the specified package
directory. Ensure that the definition of the class is prefixed with
extn
.For example,extn.extnUtils.MyUtil
.Note:Ensure that themain.js
file exists in the <INSTALL_DIR>/extensions/isccs/webpages directory. Otherwise, create themain.js
file as follows:scDefine(["dojo/_base/lang", "dojo/_base/kernel"], function(dLang, dKernel) { var scopeMap = dKernel.scopeMap; return dLang.getObject("extn", true); });
- Ensure that the utility file syntax adheres to Dojo version
1.8 standards. Additionally, you can use the following application-provided
standards:
- You can use
scDefine
instead ofdefine
. - The imported JavaScript modules can be preceded with
scbase/loader!
string. Thescbase/loader
string is a Dojo loader plug-in that is provided by the application.
A sample utility file is as follows:scDefine([ "scbase/loader!dojo/_base/lang", "scbase/loader!extn", "scbase/loader!sc/plat/dojo/info/ApplicationInfo", "scbase/loader!sc/plat/dojo/Userprefs" ], function( dLang, extnPkg, scApplicationInfo, scUserprefs ) { var myUtil = dLang.getObject("extnUtils.MyUtil", true, extnPkg); myUtil.callBasicUserPrefMethods = function() { var userPrefJson = {}; userPrefJson["currency"] = scUserprefs.getCurrency(); userPrefJson["localeCode"] = scUserprefs.getLocaleCode(); userPrefJson["organization"] = scUserprefs.getUserOrganization(); userPrefJson["userId"] = scUserprefs.getUserId(); userPrefJson["userName"] = scUserprefs.getUserName(); console.log(userPrefJson); }; myUtil.callBasicAppInfoMethods = function() { var applicationInfoJson = {}; applicationInfoJson["applicationContext"] = scApplicationInfo.getApplicationContext(); applicationInfoJson["loginPage"] = scApplicationInfo.getLoginPage(); applicationInfoJson["screenContainerInstance"] = scApplicationInfo.getSCScreenContainerInstance(); console.log(applicationInfoJson); }; myUtil.myArgsTest = function(event, bEvent, ctrl, args) { console.log("passed arguments: ", event, bEvent, ctrl, args); }; return myUtil; });
- You can use
- To use the methods of custom utility JavaScript files in
your custom behavior logic, do the following steps.
- Import the util JavaScript file in your code by following the Dojo and application-provided standards.
- Call the appropriate method. A sample code of custom behavior logic by using the methods of custom utility JavaScript.
scDefine([ "scbase/loader!dojo/_base/declare", "scbase/loader!extn/home/portlets/OrderPortletExtnUI", // Import the newly created util JS file. "scbase/loader!extn/extnUtils/MyUtil" ],function( _dojodeclare, _extnOrderPortletExtnUI, myUtil ) { return _dojodeclare("extn.home.portlets.OrderPortletExtn", [_extnOrderPortletExtnUI], { utilTest: function(event, bEvent, ctrl, args) { // Call the required util JS methods. myUtil.callBasicUserPrefMethods(); myUtil.callBasicAppInfoMethods(); myUtil.myArgsTest(event, bEvent, ctrl, args); } }); });