Let's follow up this discussion at the Neptune Community

(this forum will be kept in read-only mode)

Issue with ModelData.Update

Hi There,


I am trying to create a very simple offline app with two pages. In the first page, I display the list of business partners using sap.m.List (Name: PartnerList, setCacheType: WebSQL, setEnableCache: True, SetInitLoad:Cache). I have a Sync button which calls SYNC method of the ABAP class, which populates the PartnerList cache with latest data.  In the second page, I display the details of the partner that was selected in the first page using itemPress event.


When the second page is being displayed, the application either displays the data from the PartnerList cache or tries to call SYNC_DELTA method of ABAP class to get the latest data of the business partner.


The issue arises when I try to update PartnerList using delta data that I am receiving from SYNC_DELTA method. SYNC_DELTA returns an internal table with similar structure as PartnerList but with just one business partner details. The internal table has four fields PARTNER, BU_SORT1, BU_SORT2 and NAME_ORG1.


I am using the following code to update the delta data:

image


The delta data that I am receiving is highlighted in the below picture:

image


The following is the error that I am currently getting:

image


Can you tell me where I am going wrong?


Hi Chanukya,


firstly, you could have one list (PartnerList) and a separate work area (structure) for the detail page.  This abap work area could be binded to your SecondPage (detail page).


When you want to display the cached data, you could perform the following:

image


( data = first record of the search results).


The error you are getting

image


seems to be provoked by  modelSecondPage.oData.PARTNER not existing.   Is SecondPage should be binded to the workarea/structure I mentioned and should have some data in it.


TIP:  setting a   debugger;   statement in your code will let you debug and help you figure out what is happening.

Have a nice day,

Julian




Hi Julian,


I do have a work area structure assigned to my second page and modelSecondPage.oData.PARTNER has the partner that was selected in the first page. I can confirm it because I used console.log statement to print the partner number on the console.


You can see from the following picture how I mapped the work area structure to the second page.

image


From the following picture you can see how:

1. I am setting the data onto the second page 

2. Calling ajax to read the delta data by calling SYNC_DELTA method


image


The following screenshot shows how I am trying to update the delta data in the AjaxSuccess event:


image


You can see from the following picture that PARTNER does have the value of the partner selected. 

image



Thanks,

Chan

Hi Chan,


Two quick comments.   From my end:


1 - your forgot to add the  "[0]" in the ModelData.Find, as shown in the pic below  (also part of my previous reply).  Otherwise   data  is an array.

image



2 - 

image


Hi Julian,


I added [0] to ModelData.Find method. I clicked on the error message and found that the issue is at the following code. Can you help by looking at the code or do I need to interpret this code?


var JSONH,jsonh=JSONH=function(a,b){function c(a){var b=[];return $.each(a,function(a,c){for(var d in c)$.inArray(d,b)===-1&&b.push(d)}),b}function d(b){for(var j,l,d=b.length,e=c(b),f=e.length,g=a(d*f),h=0,i=0;h<d;++h)for(l=b[h],j=0;j<f;g[i++]=l[e[j++]]);return k.call([f],e,g)}function e(b){if("object"==typeof b[0])return b;for(var h,i,c=b.length,d=b[0],e=a((c-d-1)/d||0),f=1+d,g=0;f<c;)for(e[g++]=i={},h=0;h<d;i[b[++h]]=b[f++]);return e}function f(a){return a.length?d(a):a}function g(a){return a.length?e(a):a}function h(a,b,c,d){return n(f(a,d),b,c)}function i(a,b,c){return g(o(a,b),c)}var j=[],k=j.concat,n=(a.isArray||function(a,b){return b=a.call(j),function(d){return a.call(d)==b}}({}.toString),j.map||function(b,c){for(var d=this,e=d.length,f=a(e);e--;f[e]=b.call(c,d[e],e,d));return f},b.stringify),o=b.parse;return{pack:f,parse:i,stringify:h,unpack:g}}(Array,JSON);


Thanks,

Chan

Chan,


We went to deep into the error..   please click on the one highlighted in yellow below:


image


It should show where it failed.


Hi Julian,


I get the message when calling the method setCachePartnerList method, check the screenshot below.

image


I read it online that we need to call this method to update the cache after calling the ModelData.Update method.


Thanks,

Chan

Hi Julian,


Did you get a chance to look into my response?


Thanks,

Chan

Chan, 


The setCache.. is failing, I guess for some reason the PARTNER field did not exist in the cached object.  Something is wrong in your PartnerList model.

I am sorry, but it is extremely difficult to know what is happening without knowing the whole logic and flow in your app.


I suggest you try to debug it, step-by-step, analyze the content of each model in each step, using Chrome's developer console.  If I sit down and analyze your app, then we would be crossing the line between free support and paid consultancy services.  Hope you understand the difference.


Have a nice weekend, kind regards,

Julian


Login or Signup to post a comment