Legacy platform

Creating and using the custom utility methods

You can create custom utility methods and use them for custom behavior logic.

Procedure

  1. Create package folders in the <INSTALL_DIR>/extensions/isccs/webpages directory.
    For example, for the extn.extnUtils.MyUtil file, create extnUtils in the specified directory.
  2. 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 the main.js file exists in the <INSTALL_DIR>/extensions/isccs/webpages directory. Otherwise, create the main.js file as follows:
    scDefine(["dojo/_base/lang", "dojo/_base/kernel"], 
    
    function(dLang, dKernel) {
    	var scopeMap = dKernel.scopeMap;
    	return dLang.getObject("extn", true);
    });
  3. Ensure that the utility file syntax adheres to Dojo version 1.8 standards. Additionally, you can use the following application-provided standards:
    1. You can use scDefine instead of define.
    2. The imported JavaScript modules can be preceded with scbase/loader! string. The scbase/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;
    	
    });
  4. To use the methods of custom utility JavaScript files in your custom behavior logic, do the following steps.
    1. Import the util JavaScript file in your code by following the Dojo and application-provided standards.
    2. 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);
      		}
      }); });