Skip navigation
Currently Being Moderated

Pass in another variable thru onFolioData()

May 24, 2012 8:12 AM

Tags: #dps #adobe_dps #dps_api

This is my first time dealing with Adobe DPS and I am trying to pass another variable into the onFolioData function.

 

Right now my code looks like so:

 

 

var init_dps_api = function(productIDs, saleNumbers) {
    var onFolioData = function (data) {
        var len = data.length;

        // The library returns an array of folio descriptor objects.  Put them into a hash indexed by something more convenient (ie productId)
        for (var i = 0; i < len; i++) {
            folioDataHash[data[i].productId,data[i].saleNumber] = data[i];
        }

        var folio;
        for (var j=0; j<productIDs.length; j++){

                folio = folioDataHash[productIDs[j],saleNumbers[j]];

                if (folio) {
                    //adobe.dps.store.getPreviewImage(productIDs[j], true, 768, 1024, onPreviewImage2(productIDs[j]));
                    adobe.dps.store.getPreviewImage(productIDs[j], true, 768, 1024, onPreviewImage(productIDs[j],saleNumbers[j]));

                }
                else {
                    //console("The productId you have defined for purchase/download does not exist within your Fulfillment account");
                }
        }
    };

    var onPreviewImage = function(productID,saleNumber) {      
        var s2= "";
        var folio2 = folioDataHash[productID,saleNumber];
........

     }
}

 

In the above code you can see that I want to pass in the saleNumber, but it is breaking the page. Is there a way to do this? Can someone from the Adobe team please assist?

 

Reason for this is that from our jsp pages, we need to pass salenumbers for our Site Catalyst tracking, so I am grabbing the salenumber from the jsp page and passing it via the javascript api to trigger an Omniture function.

 

Thank you for your time and patience.

 

B

 

Message was edited by: BC_Sothebys

 
Replies
  • Bob Bringhurst
    4,644 posts
    May 29, 2007
    Currently Being Moderated
    May 25, 2012 8:07 AM   in reply to BC_Sothebys

    This user forum isn't the best place for advanced enterprise customization questions. I'll try to find someone to help you.

     
    |
    Mark as:
  • Currently Being Moderated
    May 25, 2012 10:55 AM   in reply to BC_Sothebys

    I am assuming you are looking at the callback for getFolioData(). The only parameter that gets passed is an array of folios. What other variable are you looking for? Is it a scoping issue where your variable is not available in the callback? If that is the case you could do something like this:

     

    var scope = this;

    adobe.dps.store.getFolioData(function(data){ scope.onFolioData(data) });

     

    Also, getPreviewImage() does not generate unique callbacks. So you have to wait for one callback to execute before doing another one otherwise the prior one will get overwritten by the latter one.

     
    |
    Mark as:
  • Currently Being Moderated
    May 25, 2012 11:54 AM   in reply to BC_Sothebys

    I'm not sure why you have to pass it to the callback. It sounds like it is a scoping issue since you want the variable accessible from within the callback. Did you try accessing publicationIDs or saleNumbers from the callback? It looks like they are in the global scope so they should be accessible. Are you declaring and creating the arrays before calling push()? Did you try defining a scope variable?

     
    |
    Mark as:
  • Currently Being Moderated
    May 25, 2012 1:40 PM   in reply to BC_Sothebys

    For a description of scope and closures I suggest reading any of the links from here https://www.google.com/search?q=javascript+scope+explanation.

     

    In this case your scope is changing when the callbacks are executed because they are being called from the scope of the caller not the scope from which the function is defined. To work around this I suggest using the following convention:

     

    var scope = this;

    adobe.dps.store.getFolioData(function(data){ scope.onFolioData(data) });

     

    I suggest doing this for all DPS APIs that have callbacks.

     

    For updateLibrary() you could use:

     

    var scope = this;

    adobe.dps.store.registerLibraryUpdateCompleteHandler(function(data){ scope.onLibraryUpdate(data) });

     

    Please give this a try and let me know how it goes.

     

    Once you have your scope issues sorted out you will have another problem with the following:

    adobe.dps.store.getPreviewImage(productIDs[j], true, 768, 1024, onPreviewImage(productIDs[j]));

    There are a few problems with this statement. The last parameter of getPreviewImage() takes a function. In your case, since you are executing onPreviewImage() you are passing in the return value of that function which in this case is void. What you want to do is pass the function. Another problem is that you can only have one callback at a time for getPreviewImage() so you must wait for one to complete before executing another one otherwise the first callback will get overwritten with the second. Have you tried getting the preview images from your fulfillment XML? If you have your accountId you can access your fulfillment url from http://edge.adobe-dcfs.com/ddp/issueServer/issues?accountId=. If you download and parse the XML you can get the preview image for your folio by getting the value in libraryPreviewUrl and appending with either /portrait or /landscape, ex: http://edge.adobe-dcfs.com/ddp/issueServer/issues/bdfb4254-1276-4393-a bc6-3578540b750e/libraryPreview/portrait.

     
    |
    Mark as:
  • Currently Being Moderated
    May 25, 2012 1:52 PM   in reply to BC_Sothebys

    Just a word of caution, you might get the same value passed to onPreviewImage. I forget how the call works internally in the viewer but it might be an asynchronous call which will wait for the loop to execute before executing the callbacks which will cause "j" to be the last known value of "j" for all of the callbacks.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points