cancel
Showing results for 
Search instead for 
Did you mean: 

how to call findAll method in HTML javascript for Embedded Html

Former Member
0 Kudos

Hi All,

     My sup version is 2.2 sp02, I am to using the future Embedded Html.

Now i created a front end html page, in this page i need to call a MBO operation on button click.

Is it possible? if yes could u please share some knowledge.

Note:My requirement is to display multiple MBO  screens in one screen.

through sup worksplace its not possible. Hence we are planing through Embedded Html.

Thanks in advance

suresh

Accepted Solutions (1)

Accepted Solutions (1)

david_brandow
Contributor
0 Kudos

"through sup workspace its not possible"

I assume by this you mean that the hybrid app designer doesn't support this, which I would agree with. Rather than still using the designer and utilizing the embedded HTML feature, you may find it easier to just create the entire app by hand.

"i need to call a MBO operation on button click.

Is it possible? if yes could u please share some knowledge."

I would recommend generating the JavaScript API for your MBOs, that will provide you with an API that will include the findAll function you need. The following samples/whitepapers include information how to generate and use this API:

https://cw.sdn.sap.com/cw/docs/DOC-152841

https://cw.sdn.sap.com/cw/docs/DOC-152686

https://cw.sdn.sap.com/cw/docs/DOC-152665

Former Member
0 Kudos

Hi David,

         thanks for your helping nature.

    I generated the JavaScript API for my MBOs. In the embedded Html i imported a HTML file

having below code.

Here APIs is the folder generated through wizard,

i copied APIs and (used in embedded html) HTML file to path ....Generated Hybrid App\project_name\html

<html>

<head>

      <script src="APIs/js/Callbacks.js"></script>        

        <script src="APIs/js/Camera.js"></script>        

        <script src="APIs/js/Certificate.js"></script>        

        <script src="APIs/js/datajs-1.0.3.js"></script>        

        <script src="APIs/js/ExternalResource.js"></script>        

        <script src="APIs/js/HybridApp.js"></script>        

        <script src="APIs/js/json2.js"></script>        

        <script src="APIs/js/SUPStorage.js"></script>        

        <script src="APIs/js/Timezone.js"></script>        

        <script src="APIs/js/WorkflowMessage.js"></script>    

        <script>

        function findIbase() {

          var v_mbo = new mbo5();  //MBO5 is the my MBO name   

          v_mbo.pks.put(P_LPNO_pkKey,Reg_no_input); "P_LPNO is the personalization key of MBO

          mbo5_findAll(v_mbo,null,null);  "funtion in the HybridApp.js file

        }                             

        </script>  

</head>

<body>

<form>

<label for="VIN_no_output">VIN</label>

        <div data-role="fieldcontain">

            <label for="Reg_no_input">

                Reg No.

            </label>

            <input name="Reg_no_input" id="Reg_no_input" placeholder=""               value="" type="text"

            data-mini="true">

        </div>

   <a id="GET_DATA" data-role="button" data-transition="none" href="#page1" onclick="findIbase()">

            GET CUSTOMER

        </a>

  <div data-role="fieldcontain">

            <label for="VIN_no_output">

                VIN

            </label>

            <input name="VIN_no_output" id="VIN_no_output" placeholder="" value=""

            type="text" data-mini="true">

        </div>

</form>

</body>

</html>

if is displaying in the start screen perfectly when i click the GET CUSTOMER button nothing is happening.

Is anything i did wrong?

Thanks

Suresh

Former Member
0 Kudos

Hi Suresh,

First check if the findIbase() method is getting called or not? Put alert box inside findIbase().

function findIbase() {

     alert("Hello");

     var v_mbo = new mbo5();  //MBO5 is the my MBO name  

     v_mbo.pks.put(P_LPNO_pkKey,Reg_no_input); "P_LPNO is the personalization key of MBO

     mbo5_findAll(v_mbo,null,null);  "funtion in the HybridApp.js file

}

  

If an alert box doesn't pop out then something wrong in javascript code.

Former Member
0 Kudos

Hi Shashank,

     Thanks for replay.

          I copied same code in http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro

Here i am getting popup of hello, but in emulator i am not getting any popup,

Is anything wrong with JavaScript above,

Thanks in advance

suresh

Former Member
0 Kudos

This is the major problem of Javascript. If you have any error in the code then it won't show....

There is only one way to debug javascript is to comment some code and try executing....

If your findIbase() method is working fine then there must be problem in following includes.....

Put HTML comment around following tags and try.

eg.

<!--        <script src="APIs/js/Callbacks.js"></script>        -->


        <script src="APIs/js/Callbacks.js"></script>       

        <script src="APIs/js/Camera.js"></script>       

        <script src="APIs/js/Certificate.js"></script>       

        <script src="APIs/js/datajs-1.0.3.js"></script>       

        <script src="APIs/js/ExternalResource.js"></script>       

        <script src="APIs/js/HybridApp.js"></script>       

        <script src="APIs/js/json2.js"></script>       

        <script src="APIs/js/SUPStorage.js"></script>       

        <script src="APIs/js/Timezone.js"></script>       

        <script src="APIs/js/WorkflowMessage.js"></script>   

If you have coded any java script file in the above includes then check its code first.

Former Member
0 Kudos

Hi Shshank,

            

Now alert box is coming

   function findIbase() {

                alert("Hello");

               var v_mbo = new mbo5();

               v_mbo.pks.put(P_VIN_pkKey,"yourValue");

        v_mbo.pks.put(P_LPNO_pkKey,"123456789");

        mbo5_findAll(v_mbo,null,null);

        }

But if i change to

   function findIbase() { 

     var v_mbo = new mbo5();

     v_mbo.pks.put(P_VIN_pkKey,"yourValue");

     v_mbo.pks.put(P_LPNO_pkKey,"123456789");

     mbo5_findAll(v_mbo,null,null);

     alert("Hello");

        }

alert box is not coming.

Now the doubr is, how to call MBO's in java script?

This is the method in HybridApp.js file

function mbo5_findAll(mbo5Obj, credInfo ,  errorCallback)

Thanks in advance

suresh

Former Member
0 Kudos

Hi Suresh,

Have you tried this. Provide login credentials also capture the error message in errorCallback function.

var credInfo = "supusername=username&suppassword=password";

function mbo5_findAll(mbo5Obj, credInfo ,  function(error){

     alert(error);

});

Check what is the error....

david_brandow
Contributor
0 Kudos

Its throwing an exception.  Try adding a try-catch-alert around your implementation of findlbase(), that should tell you where its having the problem.

Can you let us know what the MBO structure definitions in the generated HybridApp.js are?  e.g.

Customer = makeClass( "Fname Lname ID Address City State Zip Phone", "" );

Former Member
0 Kudos

Hi David,

MBO5 = makeClass( "INSTANCE IBASE _surrogateKey", "" );

function mbo5_findAll(mbo5Obj, credInfo ,  errorCallback)

{

    var keys = ["P_VIN_pkKey", "P_LPNO_pkKey"];

    var types = ["string", "string"];

    var objValues = [mbo5Obj.pks.P_VIN_pkKey, mbo5Obj.pks.P_LPNO_pkKey];

.

.

.

.}

Here "P_VIN_pkKey P ,_LPNO_pkKey are the Personalization keys mapped to the MBO attributes VIN , LPNO

INSTANCE, IBASE are the output parameters

i wrote my code as per

http://dcx.sybase.com/sup0220/en/com.sybase.infocenter.dc01853.0220/doc/html/vhu1349202936661.html link

2. If i successfully call the MBO how to get the MBO result.

Where i need to write the logic to get the data from MBO query.

Thanks

Suresh

david_brandow
Contributor
0 Kudos

1. If the "class" name is MBO5, then you should instantiate MBO5, not mbo5.

2. If you'd looked at the examples or read the documentation in the generated .js file, you'd know that you need to implement hwc.processDataMessage.

Former Member
0 Kudos

Hi David,

     Thanks for input. It Helped me.

<script>

        function findIbase() {

                                var v_mbo = new MBO5();

                              alert("Hello end1");

                                v_mbo.pks.put(VinPK_pkKey,"");

                              alert("Hello end2");

                              var credInfo = "supusername=supAdmin&suppassword=********";

                              var reg_value = document.getElementById('Reg_no_input').value;

                                v_mbo.pks.put(LpnoPK_pkKey,reg_value );

                                 alert(reg_value);

                              MBO5_findAll( v_mbo , credInfo ,  function(error){

                              alert("Hello end6");

                                    alert(error);

                              });

           alert("Hello end4");

         

           hwc.processDataMessage = function (incomingDataMessageValue) {

                              alert("Hello end5");

                               if (incomingDataMessageValue.indexOf("<M>") != 0) {

                                         alert("An error occurred! " + incomingDataMessageValue);

                                         }

                               var workflowMessage = new

                              WorkflowMessage(incomingDataMessageValue);

                               var values = workflowMessage.getValues();

                               var empList = values.getData("MBO5");

                               var firstEmp = empList.value[0];

                               var firstName =

                              firstEmp.getData("MBO5_INSTANCE_attribKey").value;

                              alert("The name of the first employee is " + firstName);

                               }  }

Now I am getting up-to  alert("Hello end4");

alert("Hello end5"); popup is not coming

Note:Here MBO5_findAll method is correct ( if i changed to some other "alert("Hello end4"); " is not displaying.

Thanks in advance

Sureshb

david_brandow
Contributor
0 Kudos

I'm puzzled as to why you have one function's contents inside the other's.

Former Member
0 Kudos

Hi David,

          I tried with both ways.

If i put both functions in separate

alert("Hello end5"); pop is not comming.

What i think is, we are not calling hwc.processDataMessage = function (incomingDataMessageValue) separately, hence i put it inside the onclick method findMBO( ).


Now also alert("Hello end5"); pop is not comming.

david_brandow
Contributor
0 Kudos

processDataMessage definitely gets called.

Try defining hwc before you reference it, i.e.

hwc = (typeof hwc === "undefined" || !hwc) ? {} : hwc;  // SUP 'namespace'

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Suresh,

We can call MBO methods using javascript. Please go through the following blog.

http://scn.sap.com/community/mobile/blog/2013/06/21/creating-hybrid-application-with-phonegap-and-mb...

It may be helpful.....