# Problem with my plugin with the OnDocFormSave event — Endless saving loop

**URL:** <https://community.modx.com/t/problem-with-my-plugin-with-the-ondocformsave-event-endless-saving-loop/8323>\
**Category:** Random\
**Created:** [February 15, 2025, 4:03am UTC](https://community.modx.com/t/problem-with-my-plugin-with-the-ondocformsave-event-endless-saving-loop/8323 "2025-02-15T04:03:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jber](https://community.modx.com/user_avatar/community.modx.com/jber/32/1275_2.png) [@jber](https://community.modx.com/u/jber)\
**Post date:** [February 15, 2025, 4:03am UTC](https://community.modx.com/t/problem-with-my-plugin-with-the-ondocformsave-event-endless-saving-loop/8323/1 "2025-02-15T04:03:34Z")

</div>

macOs : 15.3.1 (24D70)  
MAMP Pro 7  
Modx : 3.0.3 pl  
PHP : 8.4.2  
Collections : 4.1.1-pl

With the Collections extra, I created a product catalog, for the moment the catalog contains about thirty products.

I created a snippet to generate a json file with some product data. This snippet is run from a resource and it works fine.

Except that following the modification of the data of a product we are obliged to render the resource containing the snippet to update the json file.

So I made a plugin from my snippet that fires on the OnDocFormSave event to automatically update my json file.

But my plugin doesn’t work. When I click the save button **Modx goes into an endless loop and the json file is not created or modified**.

Here is my code:

```auto
// Génére un fichier json avec certaines données des fiches
if ($modx->resource->get('parent') != 8) {
	return;
}
$json = $modx->runSnippet('getResources', array('parents' => 8,'tpl' => 'tplJason', 'tplLast' => 'tplLastJason','processTVs' => 1, 'sortby' => 'menutitle', 'published' => 1, 'includeTVs' => 1, 'limit' => 0));
$json = "[" . "$json";
$fichierChemin = $_SERVER['DOCUMENT_ROOT'] . "/assets/data/genetics-fr.json";
$myfile = fopen($fichierChemin, "w") or die("Unable to open file!");
fwrite($myfile, $json);
fclose($myfile);

```

Could someone please point out my mistakes?

Thanks for your help

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [February 15, 2025, 8:12am UTC](https://community.modx.com/t/problem-with-my-plugin-with-the-ondocformsave-event-endless-saving-loop/8323/2 "2025-02-15T08:12:46Z")

</div>

> [@jber](#):
>
> `if ($modx->resource->get('parent') != 8) {`

Use `if ($resource->get('parent') != 8) {` instead.

---

<div class="post-metadata">

**Author:** ![jber](https://community.modx.com/user_avatar/community.modx.com/jber/32/1275_2.png) [@jber](https://community.modx.com/u/jber)\
**Post date:** [February 16, 2025, 5:38pm UTC](https://community.modx.com/t/problem-with-my-plugin-with-the-ondocformsave-event-endless-saving-loop/8323/3 "2025-02-16T17:38:21Z")

</div>

Thanks, your recommendation solved my problem, have a good day.
