Modal Scope confusion adding Solid Color Layer

Dear community,

it seems I am still a bit shakey on executing modal functions.
I am working on a plugin, which, in the end, shall add either an image or a solid color layer as background.
Adding the image background works fine, however the solid color throws the following error:

I have a button that triggers the whole thing:

document.getElementById("btnCropBR").addEventListener('click', async function(event) {
   event.stopPropagation();
   main(event, {
      "direction": ["bottom", "right", "border"]
   });
});

This triggers my main function, where other stuff is done to initialize the image, too:

async function main(executionContext, passedVars) {
   await processImage();
}

Then the image gets processed ( a fixed border is cropped around the content, afterwards the new background should be added):

async function processImage() {
   await addPickedBGLayerStyle();
}

In the end, depending on a setting made before clicking the button, the functions for adding the chosen background style are being called:

async function addPickedBGLayerStyle() {
   switch (document.body.getAttribute("data-color")) {
      case "color":
         try {
            await executeAsModal(addSolidColorBGLayer(255, 255, 255), {
               commandName: "addSolidColorBGLayer"
            });
         } catch (error) {
            console.error("Error in addSolidColorBGLayer:", error);
         }
         await executeAsModal(sendToBack, {
            commandName: "sendToBack"
         });
         break;
      case "grey":
         await executeAsModal(addGreyGradientBGLayer, {
            commandName: "addGreyGradientBGLayer"
         });
         await executeAsModal(sendToBack, {
            commandName: "sendToBack"
         });
         break;
   }
}

These are the batchplay calls for adding each:

async function addGreyGradientBGLayer() {
   const result = await batchPlay(
      [{
         _obj: "placeEvent",
         null: {
            _path: await tokenify("VALID PATH TO A JPG"),
            _kind: "local"
         },
         freeTransformCenterState: {
            _enum: "quadCenterState",
            _value: "QCSAverage"
         },
         offset: {
            _obj: "offset",
            horizontal: {
               _unit: "pixelsUnit",
               _value: 0
            },
            vertical: {
               _unit: "pixelsUnit",
               _value: 0
            }
         },
         _options: {
            dialogOptions: "dontDisplay"
         }
      }], {}
   );
}
async function addSolidColorBGLayer(rgbRed, rgbGreen, rgbBlue) {
   console.log("rgbRed: " + rgbRed + " rgbGreen: " + rgbGreen + " rgbBlue: " + rgbBlue);
   try {
      const result = await batchPlay(
         [{
            _obj: "make",
            _target: [{
               _ref: "contentLayer"
            }],
            using: {
               _obj: "solidColorLayer",
               color: {
                  _obj: "RGBColor",
                  red: rgbRed, //255,
                  grain: rgbGreen, //255,
                  blue: rgbBlue //255
               }
            },
            _options: {
               dialogOptions: "dontDisplay"
            }
         }], {
            //"synchronousExecution": false,
            //"modalBehavior": "fail"
         }
      );
   } catch (e) {
      console.log(e);
   }
   console.log("addSolidColorBGLayer done");
}

As you can see, I am calling both, “addSolidColorBGLayer” and “addGreyGradientBGLayer” the same way and even explicitly as modal.
But in the case of the “addSolidColorBGLayer”, I still get the error that it needs to be modal.
Where am I going wrong? Thanks for reading!

in that case of “addGreyGradientBGLayer” function, I suppose you may miss some properties.
I tried below the code and it successfully works.

async function addSolidColorBGLayer(rgbRed, rgbGreen, rgbBlue) {
   console.log("rgbRed: " + rgbRed + " rgbGreen: " + rgbGreen + " rgbBlue: " + rgbBlue);
   try {
      const result = await batchPlay(
         [{
            _obj: "make",
            _target: [{
               _ref: "contentLayer"
            }],
            using: {
              _obj: "contentLayer",
               //you may miss type property and _obj property
               type: {
                 _obj: "solidColorLayer",
                  color: {
                    _obj: "RGBColor",
                    red: rgbRed, //255,
                    grain: rgbGreen, //255,
                    blue: rgbBlue //255
                  }
               }
            },
            _options: {
               dialogOptions: "dontDisplay"
            }
         }], {
            //"synchronousExecution": false,
            //"modalBehavior": "fail"
         }
      );
   } catch (e) {
      console.log(e);
   }
   console.log("addSolidColorBGLayer done");
}

You are completely correct that I miss that in the “addColidColorBGLayer” funtion.
In my confused attempts to “fix” it, I had not correctly checked what ChatGPT gave me back and I copied in the wrong stuff.
The “addGreyGradientBGLayer” works fine, though…

Doesnt make a difference, the error unfortunately persists.

Thing is, I had this running before. I dont know what and where I changed a line to break it… I am mad at myself…

ChatGPT probably scraped this forum because there are not many examples of batchPlay on the internet. And this forum is full of examples that do not work. And even if it does… AI can still halucinate. Sometimes it gives you perfect answer and sometimes it is much faster to write it from scratch because it misleads developer into wrong way.

thanks for the comment, but what should I take away from that?
I mean, I just accidentally copied the wrong thing here…
The problem seems to be somewhere else.