MIGXdb listbox Input Option Values - exclude current record id

Hello.

I’m trying to find a solution how to pass a parameter into @SELECT query of the Input Option Values of the listbox.

There is a custom MIGXdb table “modx_listing_categories” with fields: id, name, parent_id, etc. Categories with parent_id=0 are root categories.

I’m trying to configure MIGXdb formtab field “parent_id” of type listbox (single select) so that the listbox contain all categories excluding the category which is currently edited in the CMP.

Input TV type: listbox,
Input Option Values:
@SELECT "- ROOT -" AS name, 0 AS id UNION SELECT name, id FROM modx_listing_categories WHERE id != "[[+current_record_id]]" ORDER BY name

Is there any way to pass the currently editing record id (modx_listing_categories.id) into the SQL Select query?

Here is the formtabs config:

{
  "formtabs":[
    {
      "MIGX_id":14,
      "caption":"General",
      "print_before_tabs":"0",
      "fields":[
        {
          "MIGX_id":97,
          "field":"id",
          "caption":"_id",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"none",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":1
        },
        {
          "MIGX_id":91,
          "field":"parent_id",
          "caption":"Parent Category",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"listbox",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"@SELECT \"- ROOT -\" AS name, 0 AS id UNION SELECT name, id FROM modx_listing_categories WHERE id !=\"[[+current_record_id]]\" ORDER BY name",
          "default":"0",
          "useDefaultIfEmpty":"0",
          "pos":3
        },
        {
          "MIGX_id":92,
          "field":"name",
          "caption":"name",
          "pos":4
        },
        {
          "MIGX_id":93,
          "field":"alias",
          "caption":"alias",
          "pos":5
        },
        {
          "MIGX_id":94,
          "field":"published",
          "caption":"Published",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"checkbox",
          "validation":"",
          "configs":{
            "allowBlank":true,
            "displayAsSwitch":true
          },
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"Set As Published==1",
          "default":"0",
          "useDefaultIfEmpty":"0",
          "pos":6
        },
        {
          "MIGX_id":95,
          "field":"deleted",
          "caption":"Deleted",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"checkbox",
          "validation":"",
          "configs":{
            "allowBlank":true,
            "displayAsSwitch":true
          },
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"Set As Deleted==1",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":7
        }
      ],
      "pos":1
    }
  ],
...
}

To create the MIGX update-window, the AJAX-request sends the request parameter “object_id” with the ID of the item you want to edit.

My guess is that instead of @SELECT you have to use @SNIPPET mySnippet (in MODX 3) or @CHUNK (in MODX 2 and then call a snippet in the chunk).
In the custom snippet you can access the value of the request parameter with $_POST['object_id'] (or maybe use $_SESSION['migxWorkingObjectid'] that seems to get set by the MIGX code). Then you have to query the database yourself and return the options in the usual format label1==value1||label2==value2.

This approach works perfectly!
Thank you, halftrainedharry!

BTW, thanks for your MIGX video series as well! Great job! Awesome and very helpful!

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.