Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Power Apps Portals
Answered

How to pass javascript variable into liquid fetch in portal ?

(0) ShareShare
ReportReport
Posted on by 40

Hi everyone !

I have a problem.

How to pass javascript variable into liquid fetch in portal ?

huuhung_0-1637678186062.png

Please help !

Thanks !

  • AkshayShah Profile Picture
    59 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

    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

  • Verified answer
    Christian Leverenz Profile Picture
    1,214 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

     @huuhung 

    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

  • huuhung Profile Picture
    40 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

    Hi @chleverenz !

    I solved the problem
    Thank you very much !

    fetch("/getPhase_WP/?proj="+proj)

     

  • huuhung Profile Picture
    40 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

    Hi @chleverenz !

    So what is the correct syntax to pass the "proj" variable to fetch ?

    Please help !

    Thanks !

  • Christian Leverenz Profile Picture
    1,214 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

    @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

  • huuhung Profile Picture
    40 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

    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

     

    huuhung_0-1637756330205.png

     

  • Christian Leverenz Profile Picture
    1,214 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

    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

  • huuhung Profile Picture
    40 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

     

    Hi @chleverenz !

    I think my Json is missing double quote
    How to show double quote in json !

    huuhung_0-1637749175839.png

     

  • huuhung Profile Picture
    40 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

    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 -%}
    ]

     

     

  • Christian Leverenz Profile Picture
    1,214 on at
    Re: How to pass javascript variable into liquid fetch in portal ?

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 60 Super User 2025 Season 1

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 1

#3
surya narayanan Profile Picture

surya narayanan 35