Nodejs URL Parameters Assistance Needed

I seem to always have issues with this and can never remember how to resolve it. I have spent the past two days reviewing the forum trying to find a solution and have not been able to find one that works. I am sure I have missed something very simple, because this is a fundamental thing, but the answer escapes me.

What I would like to do is have either a button or a link on a nodejs page that when clicked takes a user to an edit page but it could also be something that links to a details page, etc.

I have my route set up as /company/edit-national/:id

Screenshot 2024-02-10 at 10.10.19 AM

I have two buttons set up on a page. Both work the same way, but come about it differently.

The first button is an anchor button with the following attributes.

Screenshot 2024-02-10 at 10.11.39 AM

The second is a regular button with the following attributes.

Both buttons function properly and open up the page correctly.

Screenshot 2024-02-10 at 10.17.34 AM

I have created a server action that calls the for the parameter “id”.

On the layout page, I set the query parameter “id”.

On the layout page, I created a simple header that calls for a value from the server action.

On loading the page, no results are found from the server action.

Screenshot 2024-02-10 at 10.17.52 AM

There are no console errors on the page.

If I enter a default value in the server action, results are shown and displayed on the page.

Screenshot 2024-02-10 at 10.43.01 AM

I am sure this is something very simple that I have overlooked, but the solution escapes me.

You did the same mistake as this person:

$ doesn’t exist in the Server Action. You’re calling the server action “/edit”, where’s the param there? You didn’t call the server action like /edit/123

1 Like

Hi @Apple, thanks for the reply. However, I am not clear as to what the solution is here.

I created a server connect route with the parameter on the end, but I am not sure what to do with it from here.

Screenshot 2024-02-10 at 11.41.33 AM

Hi Scott,

To access values of query parameters in Server Actions from Server Connects is via $_GET variables. If you set up a GET variable $ and replace the query condition with the $ variable, the query will filter the data based on the pc_id.


Thanks @Apple and @guptast, I was able to figure it out!

@TwitchBlade, you might find this helpful.

What I ended up doing. Was this:

In the server action, I used the $_GET variable as recommended above.

I kept the page route the same, but deleted the server connect route as it was not needed.

Screenshot 2024-02-10 at 6.12.42 PM

On the layout page, I kept the query variable under the query params.

Screenshot 2024-02-10 at 6.14.16 PM

Now here is where it got interesting. Under the server connect, the “id” input parameter appeared as was expected.

Screenshot 2024-02-10 at 6.15.54 PM

However, when the lightning bolt is clicked to pick the input parameter for the “id” field, I could not see the variable under the query params.

Screenshot 2024-02-10 at 6.17.59 PM

What I had to do is switch to code view and add between the quotes in the dmx-param:id=" " code.

You would change “id” to whatever you named your variable in the query params.

That made it work for me. :slight_smile:

I am a little confused why the query params was not selectable through the picker, but I have made a note of it so will remember in the future and not have this issue again.

1 Like

Hi Scott,

Glad that it is working now. I think the confusion may be arising from the term dmx-param in Server Connect, required to access the $_GET variables on the front-end.

Did you try adding “id” to the global parameters of the layout page?
That should make it available to the picker.

I tried putting it in the “Define Global Data” with no results in the picker and then removed it.

I left it in the “Define Query Params” under App, but still not available in the picker.

Tried Global Query parameters?

Was your App ID (in the Content page) the same as the Layout page? If not parameters, cookies, and Data Store schema items will not be accessible in the picker…

Thanks @Cheese and @Hyperbytes!

As indicated, I had different values in the App ID. Once I changed that, everything works as expected. :slight_smile:

1 Like

Yes, the significance of appid does not seem well understood.
Feel a video in the making on return!


Thanks @scott. I have route parameters on server connects working fine and they send the $_GET variable to the server side and I can use them. My issue was I was trying to make the server connect dynamic to where I didn’t have to put a value in an input parameter on the server connect because where I was trying to use the server connect, there’s nowhere to put the parameter. Perhaps I’m still confused on the difference between $_PARAM and $_GET. I know how to use $_GET and $_POST I don’t understand the use case for $_PARAM. I thought it was a way to grab a param from the url on the server side without having to send it via server connect input params.

For instance, I’m trying to get the title, keywords and other meta data from values stored in the database based on the current page. There’s no way to send an id or page identifier to the server side that I can see.

@TwitchBlade, what I did was watch @Hyperbytes video here. Videos 26-29 cover using the globals server action to do the SEO tags. Then for page specific data, use the $_GET variable as outlined above.

1 Like

Thanks again. I’ll have a look.