How to pass ADOR values to JavaScript variables

219 views
Skip to first unread message

Clark Theriot

unread,
Sep 8, 2021, 1:10:47 PM9/8/21
to XMPie Interest Group
I want to pass some ADOR values to JavaScript variables to use in a function in a webpage hosted on the XMPL server as part of a Circle campaign. Is there a way to accomplish this?  If so, what is the best approach?  Any examples?

Thank you,
Clark

couch

unread,
Sep 8, 2021, 6:04:36 PM9/8/21
to XMPie Interest Group
The XMPL SDK in GitHub provides documentation and a code sample demonstrating how to do this:

I will draw your attention to the main thing that I always forget:
The  ng-app="xmp.app" moves from the body to the html tag.

The number of times I have lost hours because of that... :(

A second approach that I like to use (because I absolutely abhor Angular JS) is to toss out the xmpl library and work directly with the XMPL REST API using what ever technology you like:
Yes, it is more work, but there are more freedoms and you soon build up a library of tools.

Clark Theriot

unread,
Sep 9, 2021, 2:04:39 PM9/9/21
to XMPie Interest Group

Hi Steve,

 

I am trying your recommended direction of using the XMPL REST API and am following your video instruction in Campus.  All was working with the first couple of ADOR’s, values were coming over and I could place them on the page.  However when I added a couple more ADOR’s which are ones that I created in uPlan because they are calculated values from a SQL query I started getting the error shown below.  It is saying that the “Type is not defined”, yet I can see that the values are getting pulled as highlighted below.  The only differences are that these ADOR’s are not fields in my data but ADOR’s added that calculate a value and they are numeric though I just want them as plain text.

 

Can you help me to determine what I’m missing to trigger the error?

 

 

THIS IS THE ERROR MESSAGE TEXT FROM ABOVE SCREENSHOT:

results_v2.html?rid=clark.theriot:34 Uncaught ReferenceError: Type is not defined

    at Object.success (results_v2.html?rid=clark.theriot:34)

    at c (jquery-3.4.1.min.js:2)

    at Object.fireWith [as resolveWith] (jquery-3.4.1.min.js:2)

    at l (jquery-3.4.1.min.js:2)

    at XMLHttpRequest.<anonymous> (jquery-3.4.1.min.js:2)

 

 

 

    1. Request URL: https://print.cathedralcorporation.com/XMPieXMPL_REST_API/v1/projects/...[token info removed]…/adorvalues/context?adors=fname&adors=lname&adors=role&adors=Movie-Type-Action&adors=Movie-Type-Comedy&rid=clark.theriot
    2. Request Method: GET
    3. Status Code: 200
    4. Remote Address: 64.9.87.3:443
    5. Referrer Policy: strict-origin-when-cross-origin
  1. Response Headers
    1. access-control-allow-origin: *
    2. cache-control: no-cache
    3. content-length: 279
    4. content-type: application/json; charset=utf-8
    5. date: Thu, 09 Sep 2021 16:21:13 GMT
    6. expires: -1
    7. pragma: no-cache
    8. server: Microsoft-IIS/10.0
    9. x-aspnet-version: 4.0.30319
    10. x-powered-by: ASP.NET
  2. Request Headers
    1. :authority: print.cathedralcorporation.com
    2. :method: GET
    3. :path: /XMPieXMPL_REST_API/v1/projects/…[token info removed]…/adorvalues/context?adors=fname&adors=lname&adors=role&adors=Movie-Type-Action&adors=Movie-Type-Comedy&rid=clark.theriot
    4. :scheme: https
    5. accept: */*
    6. accept-encoding: gzip, deflate, br
    7. accept-language: en-US,en;q=0.9
    8. origin: null
    9. sec-ch-ua: "Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"
    10. sec-ch-ua-mobile: ?0
    11. sec-ch-ua-platform: "Windows"
    12. sec-fetch-dest: empty
    13. sec-fetch-mode: cors
    14. sec-fetch-site: cross-site
    15. user-agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36
  3. Query String Parametersview sourceview URL-encoded
    1. adors: fname
    2. adors: lname
    3. adors: role
    4. adors: Movie-Type-Action
    5. adors: Movie-Type-Comedy
    6. rid: clark.theriot

 

 

VALUES FROM THE BROWSER TOOL HEADER INFO:

 

{

  "recipientID": "clark.theriot",

  "serviceToken": "[token info removed]"

}

 

{

  "fname": "Clark",

  "lname": "Theriot",

  "role": "Development",

  "Movie-Type-Action": "3",

  "Movie-Type-Comedy": "6"

}

 

Thanks for your help,

Clark

results_v2.html

Wayne

unread,
Sep 9, 2021, 5:01:34 PM9/9/21
to XMPie Interest Group
You can't use Dot Notation when your name contains certain characters

Use square bracket notation instead

                        $('[name="MT-Action"]').text(resp.result['Movie-Type-Action']);
    $('[name="MT-Comedy"]').text(resp.result['Movie-Type-Comedy']);

Regards,
Wayne

Clark Theriot

unread,
Sep 9, 2021, 7:08:51 PM9/9/21
to XMPie Interest Group
Wayne,

I did not know that requirement, the brackets should resolve my issue then.

Thank you sir,
Clark

Clark Theriot

unread,
Sep 9, 2021, 9:04:28 PM9/9/21
to XMPie Interest Group
Awesome the brackets worked, I can now use the values returned by the AJAX call in the HTML. One follow up question, how would I use the values returned by the AJAX success in a different JavaScript function?  Toward the bottom of the HTML file I shared there is a function that draws a pie chart, I need to use the ADOR values returned in the success method.

Much appreciated, I'm almost there!

Again thanks,
Clark

couch

unread,
Sep 12, 2021, 11:08:27 PM9/12/21
to XMPie Interest Group
Reply all
Reply to author
Forward
0 new messages