We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36760
    • 136 Posts
    I have an existing non-MIGXdb setup that I use across multiple resources and I would like to automatically include the resource ID in a field for each new entry.

    My form tabs currently look like this:
    {"caption":"Info", "fields": [

    And I would like them to look something like this:
    {"caption":"Info", "fields": [
       {"field":"resource-id","caption":"Resource ID","inputTVtype":"text"}

    Normally I like to show some code that I was trying to work on, but I don't have much. I tried using @EVAL inside the Form Tabs area, but that threw an error. I then tried writing a plugin that populated a TV with the resource ID, which worked, but I couldn't figure out a way to pass that along to MIGX when creating a new entry.

    I'm sure the best option would be rebuilding the system in an MIGXdb, but how it's currently functioning makes sense to me (I do use MIGXdb for a lot of other things). Basically, I'm merging all the MIGX TV's from the resources I need using mergeMIGX. I want to include the resource IDs in each entry is so I can include page titles and links in the tpl file to link back to each entry's resource.

    This is what mergeMIGX looks like, in case it's relevant:
    // copied from here http://forums.modx.com/thread/?thread=41006&page=20
    // [[mergeMIGX? &tvname=`mymigxtv` &docids=`10,11,12` &tpl=`mytpl` &debug=`1`]]
    $docids = explode(',', $docids);
    if ($tv = $modx->getObject('modTemplateVar', array('name' => $tvname))) {
        $allitems = array();
        foreach ($docids as $docid) {
            $outputvalue = $tv->renderOutput($docid);
            $items = $modx->fromJSON($outputvalue);
            if (is_array($items)) {
                $allitems = array_merge($allitems, $items);
            elseif ($debug) {
                echo 'Error in '.$docid.':'.$outputvalue;
        $scriptProperties['value'] = $modx->toJSON($allitems);
    return $modx->runSnippet('getImageList', $scriptProperties);

    I appreciate any help or any suggestions!

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      you could have a plugin at OnDocFormSave, with something like that:

      $tvname = 'yourMIGXtv';
      $items = json_decode($resource->getTVValue($tvname),true);
      $newitems = array();
      if (is_array($items)){
          foreach($items as $item){
              $item['resource_id'] = $resource->get('id');
              $newitems[] = $item;


        you can buy me a beer, if you like MIGX