Another guy with broken batchplay in API 2

I’m currently porting my API1 plugin to API2. Everything ok so far with one exception.
I’m trying to get history states. When I wrap the function in an exeModal function and paste it to the console it won’t work. When I paste it to the console without the exeModal it will work as expected like it did in API1. What am I missing here?
Below code is from console with results.

const histAr = await exeModal(async () => {
      await batchPlay(
         [{
            "_obj": "get",
            "_target": [{
               "_ref": "historyState",
               "_index": 1
            }],
            "_isCommand": true,
            "_options": {}
         }], {
            "synchronousExecution": true,
            "modalBehavior": "execute"
         });
   });
undefined
await batchPlay(
         [{
            "_obj": "get",
            "_target": [{
               "_ref": "historyState",
               "_index": 1
            }],
            "_isCommand": true,
            "_options": {}
         }], {
            "synchronousExecution": true,
            "modalBehavior": "execute"
         });
[{…}]
0: {name: "raw00092.dng", itemIndex: 1, count: 3, auto: false, historyBrushSource: true, …}
length: 1
1 Like

What exactly isn’t working? What do you get after first run for histAr? I don’t see you trying to log it, so no wonder it says undefined

Thanks for helping. This is example code broken down to the basics. I usually use try/catch and in this case it would tell me that the result can’t be parsed because it’s undefined.
Thing is i’m getting undefined whith exeModal and without everything is fine and i get the desired array of data as you can see in the console results above.
From what i understood any batchplay function should be wrapped in a modal state in API V2. So it seems i have a misunderstanding here. Is there something in the docs what tells me when to use the modal state and when not? Or could you point me in the right direction please?

In exeModal() case you are assigning it to variable, but not logging it. Naturally console output is undefined. In plain BP version you are not assigning it to variable, that’s why result in console is the BP response itself.

Try in exeModal() case removing variable and see what the output is, or add console.log(histAr)

Sorry for the late reply. You are right of course. But the result is also undefined.

Hi @Michel77 , here are a few things I would try:

The Alchemist plugin could be useful for debugging this issue further if that doesn’t solve it. If the two suggestions above don’t help, please feel free to attach errors/screenshots/etc. and we can troubleshoot this further.

1 Like

I’d like to also point you to this post: Can't create a new channel using batchPlay with API 2 - #10 by simonhenke. There are known issues with certain descriptors, and I’ll note this so we can start an internal discussion.

1 Like