How to get the document uuid in a adt

josu urrutia, modified 7 Years ago. New Member Posts: 10 Join Date: 4/24/18 Recent Posts

Hi,

I'm trying to show a documents and media PDF in a Asset Publisher Template using documents and media structure field and the URL that i get is this one : https://innoval.zylk.net/en/web/guest/{

What I'm doing is this: 

  <#assign dlFile = saxReaderUtil.createXPath("dynamic-element[@name='documents']").selectSingleNode(rootElement).getStringValue() >
<p><a href="${dlFile}" target="_blank" >Download</a></p>

When i print on screen the var dlFile, it shows :

{"groupId":"20127","title":"8a66f5c8-ea38-b0f1-34dd-73447f62b882","type":"document","uuid":"8b418808-4ec6-5100-8169-368fc080611f"}

How can i get the uuid value?

I have tried to use the ?split,  a list like this:

<span>&lt;#</span><span>list dlFile as</span><span> value</span><span>&gt;</span><span> 
    </span><span> $</span><span>{</span><span>value</span><span>}</span><span> 
</span><span>&lt;/#</span><span>list</span><span>&gt;</span><span> </span>

But they doesn't work

Could someone help me??

I hope u can help me..

Lots of thanks.

Vishal Munjani, modified 7 Years ago. Junior Member Posts: 33 Join Date: 2/21/17 Recent Posts

Hello,

{"groupId":"20127","title":"8a66f5c8-ea38-b0f1-34dd-73447f62b882","type":"document","uuid":"8b418808-4ec6-5100-8169-368fc080611f"}

If your JSON is like above than you can use below code for fetching uuid.

 

&lt;#list dlFile as value&gt; 
     ${value.uuid} 
&lt;/#list&gt; 

 

Thanks

Vishal Munjani

josu urrutia, modified 7 Years ago. New Member Posts: 10 Join Date: 4/24/18 Recent Posts

Hello Vishal Munjani,

Thanks for your answer but it doesn't work, i still have a problem it says me this:

For "#list" list source: Expected a sequence or collection, but this has evaluated to a string (wrapper: f.t.SimpleScalar):

I hope u could help me.

Josu U.

Vishal Munjani, modified 7 Years ago. Junior Member Posts: 33 Join Date: 2/21/17 Recent Posts

Hello

I have tried below code and it is worked for me.Please check with below code.

<#assign dlFile=  {"groupId":"20127","title":"8a66f5c8-ea38-b0f1-34dd-73447f62b882","type":"document","uuid":"8b418808-4ec6-5100-8169-368fc080611f"}>

${dlFile.uuid}

 

Thanks

josu urrutia, modified 7 Years ago. New Member Posts: 10 Join Date: 4/24/18 Recent Posts

Hello,

Thanks for your answer, i have cheeked your code and it works.

The problem is that im in the develop enviroment and when i migrate to the production enviroment it will fail.

Is there any other solution without hard-codeing?

Thanks,

Josu U.

 

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
josu urrutia:
For "#list" list source: Expected a sequence or collection, but this has evaluated to a string (wrapper: f.t.SimpleScalar):

Based on this error message, it sounds like dlFile is a string, so you can't treat it like a list. Given that, have you tried following the blog post on Working with JSON in Freemarker to convert your dlFile variable from a string into a JSON object?

<#assign dlFile_hashmap = jsonFactoryUtil.looseDeserializeSafe(dlFile) >
${dlFile_hashmap.uuid}
josu urrutia, modified 7 Years ago. New Member Posts: 10 Join Date: 4/24/18 Recent Posts

Hello Minhchau Dang,

Thank you for your answer, the link you give me help me a lot.

Regards,

Josu U.