Expand my Community achievements bar.

SOLVED

Custom Client Context Session Store created out of reading a JSON file does not display all values in the property dropdown while creating a segment

Avatar

Level 2
I have created a new session store which reads data from the JSON file and displays the information in the client context. However, when I try to create segments based on the store properties, the generic store property window does not show the nested elements of the JSON. Here is the description The JSON Structure and the list of properties are given below. Column1 shows the JSON structure and Column2 displays the list of elements that I see when I drag a generic store property and select the cusom store. While the arrays is something that I can manage using the contains feature by checking if(prop1) contains val1 display teaser1 However, the nested values like live_videoid , timestamp etc are something that I cant fetch in the store. Please Refer to attached screenshot and package for code details
Package - https://github.com/tejasgit/aem-jabber/blob/master/customstore-1.0-SNAPSHOT.zip
[img]segment.png[/img]JSON Structure { "name":"In-A-Gadda-Da-Leela", "description":"Son, as your lawyer, I declare y'all are in a 12-piece bucket o' trouble. But I done struck you a deal: Five hours of community service cleanin' up that ol' mess you caused.", "live":{ "live_videoID":"1524", "live_timestamp_start":1433181600, "live_timestamp_end":1446487200 }, "archived":{ "videoID":"yBevB7XFcA0e9wC0q7niuA" }, "products":[ "Cloud", "Chatter" ], "tags":[ "SMB", "Enterprise" ], "speakers":[ { "speaker_name":"Test User 1", "speaker_title":"Chair, President", "image":"WtxrUJ_I.png" }, { "speaker_name":"Test User 2", "speaker_title":"CEO of Company","image":"7FsEghTJ_400x400.jpeg" }, { "speaker_name":"Test User 3", "speaker_title":"Co-Founder of Company","image":"gFVwu2oG.jpeg" } ] } List of properties seen on Generic Store name description live archived products tags speakers
1 Accepted Solution

Avatar

Correct answer by
Level 5

Hi, 

You can fetch json data into your file by ajax call using jquery.like this

$.ajax({ url: "load.json", //force to handle it as text dataType: "text", success: function(data) { //data downloaded so we call parseJSON function //and pass downloaded data var json = $.parseJSON(data); //now json variable contains data in json format //let's display a few items $('#results').html('name ' + json.name + '<br />live Videoid: ' + json.live.live_videoID+ '<br />liveTimeStampstart: '+json.live.live_timestamp_start); } });

In that way you can acess the nested data .

Hopefully you problem will be solved and if u want to display into dialog to display as option in image you can use option as name field and place

$PATH.load.json.live_videoID and $PATH.load.json.live.live_timestamp_start whatever you want.

you can see snapshot below like that[img]answeradobe.PNG[/img]

View solution in original post

2 Replies

Avatar

Level 1

Hey Ravi,

I took a quick look at your code. Only issue is that you assign directly the data via the data property (customstore.js#39). Use the JSONStore#initJSON method instead. This will transform your JSON into a flat structure. You'll be able to do things like:

ClientContext.get('customstore/live/live_timestamp_end')

After the JSONStore#initJSON call, you will need also to call JSONStore#init to initialize the store properly. To do so, you need to get rid of your listener on the initialize event, otherwise, you'll get an infinite loop. Basically, you just listen for the Profile store updates, once you know who is loaded, you can load your data.

Also, arrays are not supported, but if you really need them, the fix should be pretty easy.

Hope this helps.

Alex

Avatar

Correct answer by
Level 5

Hi, 

You can fetch json data into your file by ajax call using jquery.like this

$.ajax({ url: "load.json", //force to handle it as text dataType: "text", success: function(data) { //data downloaded so we call parseJSON function //and pass downloaded data var json = $.parseJSON(data); //now json variable contains data in json format //let's display a few items $('#results').html('name ' + json.name + '<br />live Videoid: ' + json.live.live_videoID+ '<br />liveTimeStampstart: '+json.live.live_timestamp_start); } });

In that way you can acess the nested data .

Hopefully you problem will be solved and if u want to display into dialog to display as option in image you can use option as name field and place

$PATH.load.json.live_videoID and $PATH.load.json.live.live_timestamp_start whatever you want.

you can see snapshot below like that[img]answeradobe.PNG[/img]