Adding the .parseJSON() in a serverAction step it breaks the input parameters

Hey guys,

I had in a folder, a server action with an input parameter cat_id (number). Executing some steps based on this cat_id (category_id) value…
I had to duplicate this server action and move it to another folder and in this a changed the input parameter to product_id . I needed to have the same output (get product variations) structure but based on the product_id (and not the category_id as it was).
I managed to do it and have the outpur that I want and it works.

But today I get an error in console when I select a product (and execute this server action).
I selected this server action and see that the input parameter is missing…
I deleted and added from scratch… the same result!
I checked the server action file and i think that the input parameter (product_id) is there indeed…

Here are some screenshots:

The serverAction…

The UI missing the input parameter…

And the content of my serverAction file (JSON)…

    $app->define(<<<'JSON'
    {
      "meta": {
        "$_GET": [
          {
            "type": "text",
            "name": "sort"
          },
          {
            "type": "text",
            "name": "dir"
          },
          {
            "type": "number",
            "name": "product_id"
          }
        ]
      },
      "exec": {
        "steps": [
          {
            "name": "queryProd",
            "module": "dbconnector",
            "action": "select",
            "options": {
              "connection": "conn_stock",
              "sql": {
                "type": "select",
                "columns": [
                  {
                    "table": "products",
                    "column": "prd_id"
                  },
                  {
                    "table": "products",
                    "column": "prd_Name"
                  },
                  {
                    "table": "prod_details",
                    "column": "prd_dtl_id"
                  }
                ],
                "params": [
                  {
                    "operator": "equal",
                    "type": "expression",
                    "name": ":P1",
                    "value": "{{$_GET.product_id}}",
                    "test": ""
                  }
                ],
                "table": {
                  "name": "products"
                },
                "primary": "prd_id",
                "joins": [
                  {
                    "table": "product_details",
                    "column": "*",
                    "alias": "prod_details",
                    "type": "INNER",
                    "clauses": {
                      "condition": "AND",
                      "rules": [
                        {
                          "table": "prod_details",
                          "column": "prd_dtl_Prod_id",
                          "operator": "equal",
                          "operation": "=",
                          "value": {
                            "table": "products",
                            "column": "prd_id"
                          }
                        }
                      ]
                    },
                    "primary": "prd_dtl_id",
                    "sub": {
                      "prod_variations": {
                        "type": "select",
                        "table": {
                          "name": "product_detail_prod_variations",
                          "alias": "prod_variations"
                        },
                        "key": "product_detail_id",
                        "columns": [
                          {
                            "table": "prod_variations",
                            "column": "prod_var_id"
                          },
                          {
                            "table": "prod_variations",
                            "column": "prod_var_Options"
                          },
                          {
                            "table": "prodVar_details",
                            "column": "var_Name"
                          },
                          {
                            "table": "prodVar_details",
                            "column": "var_RelCat"
                          }
                        ],
                        "params": [],
                        "primary": "prod_variations_id",
                        "joins": [
                          {
                            "table": "product_variations",
                            "column": "*",
                            "alias": "prodVar_details",
                            "type": "INNER",
                            "clauses": {
                              "condition": "AND",
                              "rules": [
                                {
                                  "table": "prodVar_details",
                                  "column": "var_id",
                                  "operator": "equal",
                                  "operation": "=",
                                  "value": {
                                    "table": "prod_variations",
                                    "column": "prod_var_id"
                                  }
                                }
                              ]
                            },
                            "primary": "var_id"
                          }
                        ],
                        "query": "select `prod_variations`.`prod_var_id`, `prod_variations`.`prod_var_Options`, `prodVar_details`.`var_Name`, `prodVar_details`.`var_RelCat` from `product_detail_prod_variations` as `prod_variations` inner join `product_variations` as `prodVar_details` on `prodVar_details`.`var_id` = `prod_variations`.`prod_var_id`"
                      }
                    }
                  }
                ],
                "query": "select `products`.`prd_id`, `products`.`prd_Name`, `prod_details`.`prd_dtl_id` from `products` inner join `product_details` as `prod_details` on `prod_details`.`prd_dtl_Prod_id` = `products`.`prd_id` where `products`.`prd_id` = ?",
                "wheres": {
                  "condition": "AND",
                  "rules": [
                    {
                      "id": "products.prd_id",
                      "field": "products.prd_id",
                      "type": "double",
                      "operator": "equal",
                      "value": "{{$_GET.product_id}}",
                      "data": {
                        "table": "products",
                        "column": "prd_id",
                        "type": "number",
                        "columnObj": {
                          "type": "increments",
                          "primary": true,
                          "nullable": false,
                          "name": "prd_id"
                        }
                      },
                      "operation": "="
                    }
                  ],
                  "conditional": null,
                  "valid": true
                }
              }
            },
            "output": false,
            "meta": [
              {
                "type": "number",
                "name": "prd_id"
              },
              {
                "type": "text",
                "name": "prd_Name"
              },
              {
                "type": "number",
                "name": "prd_dtl_id"
              },
              {
                "name": "prod_variations",
                "type": "array",
                "sub": [
                  {
                    "type": "number",
                    "name": "prod_var_id"
                  },
                  {
                    "type": "object",
                    "name": "prod_var_Options"
                  },
                  {
                    "type": "text",
                    "name": "var_Name"
                  },
                  {
                    "type": "number",
                    "name": "var_RelCat"
                  }
                ]
              }
            ],
            "type": "dbconnector_select",
            "outputType": "array"
          },
          {
            "name": "query",
            "module": "core",
            "action": "repeat",
            "options": {
              "repeat": "{{queryProd[0].prod_variations}}",
              "outputFields": [],
              "exec": {
                "steps": [
                  {
                    "name": "var_id",
                    "module": "core",
                    "action": "setvalue",
                    "options": {
                      "value": "{{prod_var_id}}"
                    },
                    "meta": [],
                    "outputType": "number",
                    "output": true
                  },
                  {
                    "name": "var_Name",
                    "module": "core",
                    "action": "setvalue",
                    "options": {
                      "value": "{{var_Name}}"
                    },
                    "meta": [],
                    "outputType": "text",
                    "output": true
                  },
                  {
                    "name": "varoptions_Array",
                    "module": "core",
                    "action": "setvalue",
                    "options": {
                      "value": "{{prod_var_Options.parseJSON().split(',')}}"
                    },
                    "meta": [],
                    "outputType": "number",
                    "output": false
                  },
                  {
                    "name": "variation_options",
                    "module": "core",
                    "action": "repeat",
                    "options": {
                      "repeat": "{{varoptions_Array}}",
                      "outputFields": [],
                      "outputFilter": "exclude",
                      "exec": {
                        "steps": [
                          {
                            "name": "varOption",
                            "module": "core",
                            "action": "setvalue",
                            "options": {
                              "value": "{{$value}}"
                            },
                            "meta": [],
                            "outputType": "number",
                            "output": false
                          },
                          {
                            "name": "curVarOption",
                            "module": "core",
                            "action": "setvalue",
                            "options": {
                              "value": "{{varOption}}"
                            },
                            "meta": [],
                            "outputType": "number",
                            "output": false,
                            "disabled": true
                          },
                          {
                            "name": "queryOptions",
                            "module": "dbconnector",
                            "action": "single",
                            "options": {
                              "connection": "conn_stock",
                              "sql": {
                                "type": "select",
                                "columns": [
                                  {
                                    "table": "product_variation_variation_options",
                                    "column": "var_opt_id"
                                  },
                                  {
                                    "table": "product_variation_variation_options",
                                    "column": "var_opt_Name"
                                  },
                                  {
                                    "table": "product_variation_variation_options",
                                    "column": "var_opt_ExtraPrice"
                                  }
                                ],
                                "params": [
                                  {
                                    "operator": "equal",
                                    "type": "expression",
                                    "name": ":P1",
                                    "value": "{{varOption}}",
                                    "test": ""
                                  }
                                ],
                                "table": {
                                  "name": "product_variation_variation_options"
                                },
                                "primary": "var_opt_id",
                                "joins": [],
                                "wheres": {
                                  "condition": "AND",
                                  "rules": [
                                    {
                                      "id": "product_variation_variation_options.var_opt_id",
                                      "field": "product_variation_variation_options.var_opt_id",
                                      "type": "double",
                                      "operator": "equal",
                                      "value": "{{varOption}}",
                                      "data": {
                                        "table": "product_variation_variation_options",
                                        "column": "var_opt_id",
                                        "type": "number",
                                        "columnObj": {
                                          "type": "increments",
                                          "primary": true,
                                          "nullable": false,
                                          "name": "var_opt_id"
                                        }
                                      },
                                      "operation": "="
                                    }
                                  ],
                                  "conditional": null,
                                  "valid": true
                                },
                                "query": "select `var_opt_id`, `var_opt_Name`, `var_opt_ExtraPrice` from `product_variation_variation_options` where `product_variation_variation_options`.`var_opt_id` = ?"
                              }
                            },
                            "output": false,
                            "meta": [
                              {
                                "type": "number",
                                "name": "var_opt_id"
                              },
                              {
                                "type": "text",
                                "name": "var_opt_Name"
                              },
                              {
                                "type": "number",
                                "name": "var_opt_ExtraPrice"
                              }
                            ],
                            "type": "dbconnector_single",
                            "outputType": "object"
                          },
                          {
                            "name": "var_opt_id",
                            "module": "core",
                            "action": "setvalue",
                            "options": {
                              "value": "{{queryOptions.var_opt_id}}"
                            },
                            "meta": [],
                            "outputType": "number",
                            "output": true
                          },
                          {
                            "name": "var_opt_Name",
                            "module": "core",
                            "action": "setvalue",
                            "options": {
                              "value": "{{queryOptions.var_opt_Name}}"
                            },
                            "meta": [],
                            "outputType": "text",
                            "output": true
                          },
                          {
                            "name": "var_opt_ExtraPrice",
                            "module": "core",
                            "action": "setvalue",
                            "options": {
                              "value": "{{queryOptions.var_opt_ExtraPrice}}"
                            },
                            "meta": [],
                            "outputType": "number",
                            "output": true
                          }
                        ]
                      }
                    },
                    "output": true,
                    "meta": [
                      {
                        "name": "$index",
                        "type": "number"
                      },
                      {
                        "name": "$number",
                        "type": "number"
                      },
                      {
                        "name": "$name",
                        "type": "text"
                      },
                      {
                        "name": "$value",
                        "type": "object"
                      },
                      {
                        "name": "var_opt_id",
                        "type": "number",
                        "sub": []
                      },
                      {
                        "name": "var_opt_name",
                        "type": "text",
                        "sub": []
                      },
                      {
                        "name": "var_opt_ExtraPrice",
                        "type": "number",
                        "sub": []
                      }
                    ],
                    "outputType": "array"
                  },
                  {
                    "name": "",
                    "options": {}
                  }
                ]
              }
            },
            "output": true,
            "meta": [
              {
                "name": "$index",
                "type": "number"
              },
              {
                "name": "$number",
                "type": "number"
              },
              {
                "name": "$name",
                "type": "text"
              },
              {
                "name": "$value",
                "type": "object"
              },
              {
                "name": "prod_var_id",
                "type": "number"
              },
              {
                "name": "prod_var_Options",
                "type": "object"
              },
              {
                "name": "var_Name",
                "type": "text"
              },
              {
                "name": "var_RelCat",
                "type": "number"
              },
              {
                "name": "var_id",
                "type": "number",
                "sub": []
              },
              {
                "name": "var_Name",
                "type": "text",
                "sub": []
              },
              {
                "name": "variation_options",
                "type": "array",
                "sub": [
                  {
                    "name": "var_opt_id",
                    "type": "number",
                    "sub": []
                  },
                  {
                    "name": "var_opt_name",
                    "type": "text",
                    "sub": []
                  },
                  {
                    "name": "var_opt_ExtraPrice",
                    "type": "number",
                    "sub": []
                  },
                  {
                    "name": "var_opt_Name",
                    "type": "text",
                    "sub": []
                  }
                ]
              }
            ],
            "outputType": "array"
          }
        ]
      }
    }
    JSON
    );
    ?>

-Php
-Wappler 6.0 beta 3 - STABLE

Any ideas what to search and how to fix it would be appreciated!

So what is the code for this server action on the page?

I have uploaded a screenshot of the server action and the content of the generated JSON file…

You mean something else?

I mean the server connect component code on your page.

you mean where do I call this server action?

No … i mean the server connect component on your page.
Click here:

Open code view and copy the code this component has there…

here it is…

<dmx-serverconnect id="srvc_getVar_OptionList" url="dmxConnect/api/admin/orders/specifics/variations_list_perCategory.php"></dmx-serverconnect>

There seems to be some syntax error or corruption in your server action code.
For example in your steps i see {{prod_var_Options.parseJSON().split(',')}} - but i don’t see where this value comes from.

I am 99% sure that’s a copy/paste/edit issue you are having here.

Even if I add by hand the 3 inputs (I forgot that I had also Sort and Dir for a multiple query) it just ignores them all…
I quit copletely wappler reopened and still nothing…

<dmx-serverconnect id="srvc_getVar_OptionList" url="dmxConnect/api/admin/orders/specifics/variations_list_perCategory.php" dmx-param:product_id="" dmx-param:sort="" dmx-param:dir="" noload="true"></dmx-serverconnect>

So, answering to your reply…
My code works as it should.

This comes from a nested query

and is the prod_var_options JSON field that contains the variations for the specific product:

So, in order not to waste your valuable time brother by asking questions, you suggest I should start from scratch and create the server action again?

You can either start from scratch or try removing the steps one by one to see which one causes the issue.

1 Like

Thanks brother!

@Teodor, sorry to bother again…

I found which step is causing the mistyrious lost of my serverConnect input parameter
It is the line that your cat eye caught:

Until that point the input product_id is there:

If I insert the prod_var_Options.parseJSON().split(‘,’) I loose my product_id input:

I really cannot understand why this is happening…
My outpout is valid and correct! Is this possible a step to cause loosing the ability to use the input parameter of a serverConnect?

Anyway, prod_var_Options is the JSON field of my table holding the ids of the valid Variations for that product (a string, comma separated created using tagify).

Is there any other way to get its values in a repeat and get the related info I need?

Help… Any idea would be much appreciated

Hey @Teodor,

This looks like a bug to me…

My final report:
1)
As soon as I add the .pardeJson() in a serverAction step it breaks the input parameters (IN THE UI)

2)
But the input parameter is there. If I assign it by hand in my code it works

3)
BUT, although it works and I get the variation/option list I need it throughs an error:
dmxAppConnect.js:7 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘apply’)
at n.runJS (dmxAppConnect.js:7:97153)
at n._execStep (dmxAppConnect.js:7:47020)
at dmxAppConnect.js:7:46449

I attach a video describing the problem:

Can you please take a look at that?

Kind reminder…

Can anybody check if:
Having a table including a json field with ids (example: “1, 6, 8” )
Creates server action, set a GET parameter and

  1. pull the Json field value
  2. add a repeat based on jsonField. parseJSON(). split(’, ')

In step 2, do you loose the input parameter of the server action?

@Teodor can you please take a look at this?

Can we use .parseJSON() in serverAction steps?

I am about to regret using JSON fields for handling tagify values and rebuild my project using subtables instead…
I just need a confirmation before I turn the up side down in my project

Sorry but from all your posts, screenshots, video i really have hard time understanding what issue exactly are you reporting?
You are using parseJSON() in some of your Server Action steps and this makes the GET param not appear in the UI on the page where your Server Action is used - is that the issue you are reporting?

Yes…
Actually it breaks the whole serverConnect output… (no outputs at all).

Ok we are going to check that.

1 Like

I am sorry but I am very confused from this behavior that’s why I’m confusing you also…

Actualy this started because I duplicated the serverAction and work in different way BUT I kept the data exported exactly the same (this way I avoided changing all the client-side bindings that was working fine with the previous serverAction that I haven’t used .paseJSON() in it).

That’s why I didn’t understand exactly what is going on.


Because on front-side is working, as you can see at the image above that I assign a query for a selection’s option dmx-repeat. I cannot assign it through the UI because it is not there but since it was already assigned using the previous serverAction it is working and get the select options as I should.

Anyway, I think as soon as you check it you understand if I did something wrong or it is due to serverAction/parseJSON behavior.