web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How to pass javascript...
Power Pages
Unanswered

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 !

Categories:
I have the same question (0)
  • H V Profile Picture
    1,510 on at

    Hi @huuhung 

     

    You can pass js variable like this:

    value="{{proj}}"

     

    --------------------------
    If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people!

  • Christian Leverenz Profile Picture
    1,214 on at

    Hi @huuhung ,

    the solution from @hardikv  works only, if your variable is stored in a liquid variable. It does not work at clientside javascript, because you pass in the variable at the client and the liquid is executed at the server.

    So, either you know the value of proj on the server or you have to take another approach:

    Either using the new fetch api call (currently preview) described unter https://docs.microsoft.com/en-us/powerapps/maker/portals/read-operations 

    or create a new template, a pagetemplate and a page as decribed here:

    https://colinvermander.wordpress.com/2017/04/17/dynamics-365-portals-use-liquid-to-return-json-or-xml/ and the basics are described here (there is html rendered, but you can render json of course, too):

    https://docs.microsoft.com/en-us/powerapps/maker/portals/liquid/template-tags#fetchxml

     

    I use this approach very frequently so the portal has some "api services" andpoints for me which are queryable via javascript.

    Hope this helps,

      Christian

  • Christian Leverenz Profile Picture
    1,214 on at

    Ah, and another more general hint: do not forget to pass in no-lock="true" in the fetch (if its ok for you). This dramatically enhances performance on all systems and prevents locks on the database...

  • huuhung Profile Picture
    40 on at

    Thanks for reply !

    I also entered {{proj}} but it's not work 😞

     

    huuhung_0-1637683045042.png

     

  • huuhung Profile Picture
    40 on at

    Thanks for reply !

     

    Can I do it like this?
    {% assign test = proj %}
    Because if I pass the value directly to the variable test then in the fetchxml sentence will be {{test}} then it work

  • Christian Leverenz Profile Picture
    1,214 on at

    Hi @huuhung ,

    I'm afraid you can't.

    The model of execution is diffrent: liquid code is executed on the webserver and the javascript is executed in the browser. So you need either to use the read web api (did not try yet) or set up a dedicated page which only serves json. Yo can pass in your proj with something like fetch("/myjsonpage/?proj=abcdef").then(function(result)...

    and on the page carrying the code for the fetch you can read the parameter via {% assign myproj = request.params["proj"] %}

    you should check whether a proj was passed in and then either return nothing or all, whatever fits to your needs.

    Keep on portalling,

      Christian

  • huuhung Profile Picture
    40 on at

    I pass "proj" parameter when there is an onchange event on select tag to get the value and then put the proj variable in the fetch statement

  • huuhung Profile Picture
    40 on at

    huuhung_0-1637685375369.png

     

  • Christian Leverenz Profile Picture
    1,214 on at

    Hi @huuhung ,

    i attached a few files and images which may help. First, i created a template called levchr-dependenfetchservice with the content of fetchservicetemplate.txt. I set the contenttype to application/json which makes debugging for me easier 🙂

    Then i created a pagetemplate for that webtemplate and from that pagetemplate a webpage. I can access that webpage now with a parameter called id. the call ist something like /dependenfetchservice/?id=936b419f-9f4b-e111-bb8d-00155d03a715 and the output is something like:

    chleverenz_0-1637693833192.png

    Then i created another template (which would take your function) which consumes that service.

    The output of the service is mapped to an optionlist which is put in the targetselect. The code is also attached in fetchpagetemplate.txt .

    The output after selecting an account was somthing like:

    selectresult.png

    May be this example helps you to figure out how to select the project related stuff (which i of course do not have 🙂

    Have fun,

      Christian

    PS !Important! untick the "use header and footer" box for the servicetemplate. If you forgetto do that, you get an html page instead of a json output...

  • huuhung Profile Picture
    40 on at

    I have received information from you. I am testing and will report back the results soon.
    Thank you very much!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard