Hi everyone !
I have a problem.
How to pass javascript variable into liquid fetch in portal ?
Please help !
Thanks !
Announcements
Hi everyone !
I have a problem.
How to pass javascript variable into liquid fetch in portal ?
Please help !
Thanks !
Hello huuhung,
i have same issue for get Selected value from HTML page and filter in fetch xml for get data. so i found one solutions like below :
//Append Current proj value to URL
window.history.replaceState(null, null, "?<stringname>="+<passvalue like proj>);
//Assign value to Liquid Script
{% assign dynamicVariableName = request.params['stringname'] %}
and this Variable you should filter in Fetch XML :
<condition attribute="createdon" operator="on-or-after" value="{{dynamicVariableName}}" />
If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people!
Thanks & Regards,
Akshay Shah
welcome, glad to be able to help. If the problem is solved please consider to mark it as solved in this thread.
Thanks a lot,
Christian
Hi @chleverenz !
So what is the correct syntax to pass the "proj" variable to fetch ?
Please help !
Thanks !
i @huuhung ,
this is due to the url formatting. When you use ${} expressions, you have to use backticks ( ` ) and not signlequotes ( ' ) . I think, a unixguru was there when they designed this 🙂
see here for details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Have fun,
Christian
Hi @chleverenz !
I found the cause of the error
If I enter the url directly then OK
Otherwise, when I enter the variable in fetch, I get an error
Please help !
Thanks
Hi @huuhung ,
true. Did it work with the quoted hashkeys? JSON definition says, the keys have to be in quotes, somtimes the jason parsers also accept unquoted keys.
But i usually quote them for standard sake 🙂
Cheers,
Christian
Hi @chleverenz
It's not work !
error : Uncaught (in promise) SyntaxError: Unexpected token L in JSON at position 3
{%- assign test = request.params["proj"] -%}
{%- fetchxml my_query -%}
<fetch mapping="logical" output-format="xml-platform" version="1.0" distinct="false" >
<entity name="bsd_phaseslaunch" >
<attribute name="bsd_phaseslaunchid" />
<attribute name="bsd_name" />
<attribute name="createdon" />
<order attribute="bsd_launchedon" descending="true" />
<filter type="and" >
<condition attribute="bsd_projectid" operator="eq" value="{{test}}" />
<condition value="100000000" attribute="statuscode" operator="eq" />
</filter>
</entity>
</fetch>
{%- endfetchxml -%}
[
{%- for phase in my_query.results.entities -%}
{"PhaseID":"{{phase.bsd_phaseslaunchid}}","Name":"{{phase.bsd_name}}"}
{%- unless forloop.last -%},{%- endunless -%}
{%- endfor -%}
]
Hi @huuhung ,
unfortunately, you killed the squared brackets ( [ ] around all objects) 🙂 - happens 🙂
I personally (but is my be no issue) prefer not to have linebreaks in the json itself. Therefor, i usually have the curly brackets (opening and closing) on the same line as the output
Kind regards,
Christian
Lucas001
60
Super User 2025 Season 1
Fubar
55
Super User 2025 Season 1
surya narayanan
35