HybridApp.js

In the HybridApp.js file, helper JavaScript structures are generated for the selected MBOs, and for the MBOs that have one-to-one, or one-to-many relationships.

Functions against selected MBO operations and object queries are also generated.

Example 1

This is an example of the generated JavaScript for the Department MBO and Employee MBO in which the Department MBO has a one-to-many relationship with the Employe MBO.
/**   
 * Returns The constructor of an mbo structure. This is helper function for creating MBO's operations or namedQuery input structure   
 * @param attributes The parameters of an mbo operation, separated by one space. If the parameters map to MBO's attributes, use attributes name instead.   
 * @param children The relationship names of an mbo operation's parameters or the array type of parameters, separated by one space.   
 */   
function makeClass(attributes, children) {   
    var attributeNames = attributes.split(' ');   
    var attributeCount = attributeNames.length;   
    var childrenNames = children.split(' ');   
    var childrenCount = childrenNames.length;   
     
      
    function constructor() {   
        for (var i = 0; i < attributeCount; i++)   
        {   
               var name = attributeNames[i];   
               var subAttr = null;   
                  
               //If the name contains . which should be structure,    
               while( name.indexOf('.') >0 )   
               {   
                       var part = name.substring( 0, name.indexOf('.'));   
                       if ( subAttr )   
                       {   
                              subAttr.part = new Object();   
                              subAttr = subAttr.part;   
                       }else    
                       {   
                           this[part]= new Object();   
                           subAttr = this[part];   
                       }   
                       name = name.substring( name.indexOf('.')+1, name.length);   
               }   
                  
               if ( subAttr )   
               {   
                       subAttr[name]= new Object();   
            }else {   
                       this[name] = new Object();   
               }   
        }   
         
        for (var i = 0; i < childrenCount; i++) {   
            this[childrenNames[i]] =[];   
            this['OldValue_' + childrenNames[i]] =[];   
        }   
           
        this['__state'] ="";   
        this['pks'] = {};   
         
        var self = this;   
    
        this['pks'].put = function(pkName, pkValue ) {   
               self['pks'][pkName] = pkValue ;   
        }   
    }   
    return constructor;   
}       

Set the "__state" field to "add," "delete," or "update" to add or delete an MBO, or to update a child MBO to a parent MBO, respectively. 

Use the "pks" field to set values for operation parameters that have personalization keys.

Example 2

This example shows the JavaScript structures generated for a Department MBO and Employee JavaScript:

/**   
 * Returns Department MBO structure.    
 * Used by JavaScript functions of department_create_submit,department_create_onlineRequest,department_update_submit,department_update_onlineRequest,department_delete_submit,department_delete_onlineRequest,department_findAll,department_findByPrimaryKey   
 * @param dept_id The "dept_id" is attribute field of MBO Department   
 * @param dept_name The "dept_name" is attribute field of MBO Department   
 * @param dept_head_id The "dept_head_id" is attribute field of MBO Department   
 * @param Employee is MBO Employee javaScript structure array which representing the MBO Department to MBO Employee one to many relationship   
 */      
Department = makeClass( "dept_id dept_name dept_head_id", "Employee" );       
/**   
 * Returns Employee MBO structure.    
 * Used by JavaScript functions of employee_create_submit,employee_create_onlineRequest,employee_update_submit,employee_update_onlineRequest,employee_delete_submit,employee_delete_onlineRequest,employee_findAll,employee_findByPrimaryKey   
 * @param emp_id The "emp_id" is attribute field of MBO Employee   
 * @param manager_id The "manager_id" is attribute field of MBO Employee   
 * @param emp_fname The "emp_fname" is attribute field of MBO Employee   
 * @param emp_lname The "emp_lname" is attribute field of MBO Employee   
 * @param dept_id The "dept_id" is attribute field of MBO Employee   
 * @param street The "street" is attribute field of MBO Employee   
 * @param city The "city" is attribute field of MBO Employee   
 * @param state The "state" is attribute field of MBO Employee   
 * @param zip_code The "zip_code" is attribute field of MBO Employee   
 * @param phone The "phone" is attribute field of MBO Employee   
 * @param status The "status" is attribute field of MBO Employee   
 * @param ss_number The "ss_number" is attribute field of MBO Employee   
 * @param salary The "salary" is attribute field of MBO Employee   
 * @param start_date The "start_date" is attribute field of MBO Employee   
 * @param termination_date The "termination_date" is attribute field of MBO Employee   
 * @param birth_date The "birth_date" is attribute field of MBO Employee   
 * @param bene_health_ins The "bene_health_ins" is attribute field of MBO Employee   
 * @param bene_life_ins The "bene_life_ins" is attribute field of MBO Employee   
 * @param bene_day_care The "bene_day_care" is attribute field of MBO Employee   
 * @param sex The "sex" is attribute field of MBO Employee   
 */      
Employee = makeClass(  "emp_id manager_id emp_fname emp_lname dept_id street city state zip_code phone status ss_number salary start_date termination_date birth_date bene_health_ins bene_life_insbene_day_care sex" ,  ""  ); 

If there is one parameter that does not map to the MBO’s attribute, the JavaScript structure for the MBO’s function input parameters is generated. This example shows an MBO called Banks where the dataSource is an SAP® object. In addition to the Banks JavaScript structure,  the BANK_LIST and Banks_getList JavaScript structures are also generated.

/****************** DEFINITION OF MBO JAVASCRIPT STRUCTURE ************************/       
/**   
 * Returns BANK_LIST structure   
 * @param BANK_CTRY The"BANK_CTRY" is the parameter field of BANK_LIST.   
 * @param BANK_NAME The"BANK_NAME" is the parameter field of BANK_LIST.   
*/   
BANK_LIST = makeClass("BANK_CTRY BANK_NAME" ,"" )       
/**   
 * Returns Banks_getList structure. Used by functions of banks_getList_submit and banks_ getList_onlineRequest   
 * @param BANK_CTRY The "BANK_CTRY " is the parameter field of the operation of getList.   
 * @param BANK_LIST The "BANK_LIST " is the array parameter field of the operation of getList.   
 */   
Banks_getList = makeClass( "BANK_CTRY", "BANK_LIST" );   
    
     
/**   
 * Returns Banks MBO structure.    
 * Used by JavaScript functions of banks_findAll,banks_getByName   
 * @param BANK_CTRY The "BANK_CTRY" is attribute field of MBO Banks   
 * @param BANK_KEY The "BANK_KEY" is attribute field of MBO Banks   
 * @param BANK_NAME The "BANK_NAME" is attribute field of MBO Banks   
 * @param CITY The "CITY" is attribute field of MBO Banks   
 * @param BAPI_BANK_GETLIST_BANK_LIST1 is MBO BAPI_BANK_GETLIST_BANK_LIST1 javaScript structure array which representing the MBO Banks to MBO BAPI_BANK_GETLIST_BANK_LIST1 one to many relationship   
 */      
Banks = makeClass(  "BANK_CTRY BANK_KEY BANK_NAME CITY" ,  "BAPI_BANK_GETLIST_BANK_LIST1" ); 

Example 3

Global variables are generated for each MBO operation. You can reference these global variables in your code when you process incoming data to check which action was performed for the incoming message.

/*   
* Global variables for Customer actions   
 */   
Customer.createAction = "Customer_create";   
Customer.updateAction = "Customer_update";   
Customer.deleteAction = "Customer_delete";   
Customer.findAllAction = "Customer_findAll";
Customer.findByPrimaryKeyAction =  "Customer_findByPrimaryKey" ; 

Example 4

Two versions of  JavaScript functions are generated for the MBO’s create, read, update, delete operations. For example, for a create operation there is a create_submit function and create_onlinerequest function generated.  This example shows the generated JavaScript function for the Department create operation:

/**   
 * Returns void. This is submit operation, therefore no message will be sent back to user by the hybrid web container   
 * @param departmentObj which is the instance of Department JavaScript structure. Values should be set for this instance.    
 * @param credInfo, It is string value , should be something look like "supusername=username&suppassword=password".    
 * @param keepOpen, If this set to true, the Hybrid App will be kept open, otherwise, the hybrid web container will close the Hybrid App.     
*/                   
           
function department_create_submit(departmentObj, credInfo, keepOpen)   
{   
    //Collect values from departmentObj customerObj and fill the action parameters   
    var keys = ["Department_create_dept_id_paramKey", "Department_create_dept_name_paramKey", "Department_create_dept_head_id_paramKey"];   
    var types = ["int", "string", "int"];   
    var objValues = [departmentObj.dept_id, departmentObj.dept_name, departmentObj.dept_head_id];   
       
    var workflowMessageToSend = new WorkflowMessage("");   
       
        workflowMessageToSend.setHeader("");   
       
        workflowMessageToSend.setRequestAction( "Department_create");   
           
        createMessageValues( workflowMessageToSend.getValues(), keys, types, objValues );    
        
    if ( departmentObj.Employee && departmentObj.Employee.length > 0 ) 
// we have list object array    
    {   
        var department_employees = new MessageValue();   
        department_employees.key = "Department_employees";   
        department_employees.isNull = false;   
        department_employees.type = "LIST";   
     
        var employeekeys = ["Employee_emp_id_attribKey", "Employee_manager_id_attribKey", "Employee_emp_fname_attribKey", "Employee_emp_lname_attribKey", "Employee_dept_id_attribKey", "Employee_street_attribKey", "Employee_city_attribKey", "Employee_state_attribKey", "Employee_zip_code_attribKey", "Employee_phone_attribKey", "Employee_status_attribKey", "Employee_ss_number_attribKey", "Employee_salary_attribKey", "Employee_start_date_attribKey", "Employee_termination_date_attribKey", "Employee_birth_date_attribKey", "Employee_bene_health_ins_attribKey", "Employee_bene_life_ins_attribKey", "Employee_bene_day_care_attribKey", "Employee_sex_attribKey"];   
        var employeetypes = ["int", "int", "string", "string", "int", "string", "string", "string", "string", "string", "string", "string", "decimal", "DateTime", "DateTime", "DateTime", "string", "string", "string", "string"];   
       
              var employeeValues = [];   
       
           
        for( var employeei = 0 ; employeei < departmentObj.Employee.length ; employeei ++ )   
        {   
               var employeelc  = new MessageValueCollection();   
               employeelc.key = guid();   
               employeelc.parent = "Department_employees";   
               employeelc.parentValue = department_employees   
               employeelc.state = departmentObj.Employee[employeei].__state;   
           
               var employeeObjValues = [];   
           
               employeeObjValues.push( departmentObj.Employee[employeei].emp_id);
           
               employeeObjValues.push( departmentObj.Employee[employeei].manager_id);    
               employeeObjValues.push( departmentObj.Employee[employeei].emp_fname);
           
               employeeObjValues.push( departmentObj.Employee[employeei].emp_lname);
           
               employeeObjValues.push( departmentObj.dept_id);    
               employeeObjValues.push( departmentObj.Employee[employeei].street);
           
               employeeObjValues.push( departmentObj.Employee[employeei].city);
           
               employeeObjValues.push( departmentObj.Employee[employeei].state);
           
               employeeObjValues.push( departmentObj.Employee[employeei].zip_code);
           
               employeeObjValues.push( departmentObj.Employee[employeei].phone);
           
               employeeObjValues.push( departmentObj.Employee[employeei].status);
           
               employeeObjValues.push( departmentObj.Employee[employeei].ss_number);
           
               employeeObjValues.push( departmentObj.Employee[employeei].salary);
           
               employeeObjValues.push( departmentObj.Employee[employeei].start_date);    
               employeeObjValues.push( departmentObj.Employee[employeei].termination_date);    
               employeeObjValues.push( departmentObj.Employee[employeei].birth_date);    
               employeeObjValues.push( departmentObj.Employee[employeei].bene_health_ins);    
               employeeObjValues.push( departmentObj.Employee[employeei].bene_life_ins);    
               employeeObjValues.push( departmentObj.Employee[employeei].bene_day_care);    
               employeeObjValues.push( departmentObj.Employee[employeei].sex);    
                        
               createMessageValues( employeelc ,employeekeys , employeetypes, employeeObjValues );   
           
                //Find this Employee old values if it has.   
            for( var oldValueemployeei = 0 ; oldValueemployeei < departmentObj.OldValue_Employee.length ;
        oldValueemployeei ++ )   
                {      
                    if ( departmentObj.OldValue_Employee[ oldValueemployeei ].emp_id ===
          departmentObj.Employee[  employeei].emp_id
        )   
                    {   
                        var oldValue_employeekeys = ["_old.Department.emp_id", "_old.Department.manager_id", "_old.Department.emp_fname", "_old.Department.emp_lname", "_old.Department.dept_id", "_old.Department.street", "_old.Department.city", "_old.Department.state", "_old.Department.zip_code", "_old.Department.phone", "_old.Department.status", "_old.Department.ss_number", "_old.Department.salary", "_old.Department.start_date", "_old.Department.termination_date", "_old.Department.birth_date", "_old.Department.bene_health_ins", "_old.Department.bene_life_ins", "_old.Department.bene_day_care", "_old.Department.sex"];   
                        var oldValue_employeetypes = ["INT", "INT", "STRING", "STRING", "INT", "STRING", "STRING", "STRING", "STRING", "STRING", "STRING", "STRING", "DECIMAL", "DATE", "DATE", "DATE", "STRING", "STRING", "STRING", "STRING"];   
                        var oldValue_employeeValues = [];       
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].emp_id);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].manager_id);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].emp_fname);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].emp_lname);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].dept_id);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].street);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].city);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].state);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].zip_code);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].phone);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].status);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].ss_number);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].salary);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].start_date);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].termination_date);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].birth_date);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].bene_health_ins);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].bene_life_ins);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].bene_day_care);   
                        oldValue_employeeValues.push( departmentObj.OldValue_Employee[oldValueemployeei].sex);   
           
                        createMessageValues( employeelc,oldValue_employeekeys , oldValue_employeetypes, oldValue_employeeValues );   
          
                       break;   
                    }         
           
                } 
// end of old values --->   
           
                employeeValues.push( employeelc);   
                        
        }   
     
           
        department_employees.setValue(employeeValues);   
           
        workFlowValues.add( department_employees.getKey(), department_employees);   
                   
    }   
     hwc.doSubmitWorkflow_CONT( credInfo, workflowMessageToSend.serializeToString(),workflowMessageToSend.getHasFileMessageValue());   
}                   
/**   
 * Returns void. This is an onlineRequest operation, therefore the message will be sent back to the user by the Hybrid Web Container. 
Handle the result in the function customAfterDataReceived(incomingWorkflowMessage)defined in Custom.js.   
 * @param departmentObj, which is the instance of Department JavaScript structure. Values should be set for this instance.   
 * @param credInfo, which is a string value, and should look like "supusername=username&suppassword=password".    
 * @param errorCallback, name of the function to be called if an online request fails.   
 */        
                         
function department_create_onlineRequest(departmentObj, credInfo , errorCallback)   
{   
    var keys = ["Department_create_dept_id_paramKey", "Department_create_dept_name_paramKey", "Department_create_dept_head_id_paramKey"];   
.......   
....   
..