0

I am trying to retrieve around 2,500 rows from my Data Extension into a CloudPage so I can use it for some dynamic forms using JS.

I would like to know what would be the best way to retrieve this data and store into a JS object? I'm looking at SSJS and AMPScript but there doesn't seem to be an option to just get all the data and turn into some sort of JSON string on the page.

Any suggestions what the best method here would be?

1 Answer 1

1

For this purpose, if you'd really like to go down the path of building JSON and using js to manipulate the data, here is what I can recommend.

Step 1: Create a new code resource under the Cloudpage collection and set it as a text format since the output from this page is a simple text (url example: https://cloud.email.xyz.com/json-processing). Then you'd retrieve the data using AMPscript within this page. The next step is to build your JSON in this page using Concat AMPscript function.

Example:

/*BUILD JSON*/
   SET @delimeter = ""
   SET @rowString = Concat(
     @delimeter,
     '{"EmailAddress":"'                  , @EmailAddress,
     '","FirstName":"'                    , @FirstName,
     '","LastName":"'                     , @LastName,
     '","MailingCity":"'                  , @MailingCity,
     '","MailingState":"'                 , @MailingState,
  '"}'
   )

Step 2: Create a landing page resource within the same cloudpage collection and this would be your front-end page with forms and fields with your js. You could have your js within the html page or create a separate script page depending on the complexity and the use case.

  • To Retrieve: You can then use the js to retrieve the json data from the 1st code resource you have created. You'd be using the getJSON method to retrieve the data.

Example: var url = "https://cloud.email.xyz.com/json-processing";

Note: This is a high-level solution provided under the assumption that OP wants to use js and build JSON using AMPscripts.

2
  • Hey Brad, I’ve actually got used another method using SSJS on the initial landing page. However this takes around 5s to loads all the rows. Is there any speed benefit to using AMPScript? I can see you have a secondary page for the JSON data, I take it this is to load the records asynchronously? Oct 1, 2018 at 1:06
  • sweet. yeah AMPscript will definitely be faster than using SSJS, however, in this scenario, you're making a getjson request through js and this would be a client-side processing which won't affect your front-end load. Oct 1, 2018 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.