# Batchplay Loop synchronous not working

**URL:** <https://forums.creativeclouddeveloper.com/t/batchplay-loop-synchronous-not-working/6078>\
**Category:** UXP Plugin API\
**Tags:** uxp, javascript\
**Created:** [March 24, 2023, 9:12am UTC](https://forums.creativeclouddeveloper.com/t/batchplay-loop-synchronous-not-working/6078 "2023-03-24T09:12:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cintamani](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@cintamani](https://forums.creativeclouddeveloper.com/u/cintamani)\
**Post date:** [March 24, 2023, 9:12am UTC](https://forums.creativeclouddeveloper.com/t/batchplay-loop-synchronous-not-working/6078/1 "2023-03-24T09:12:18Z")

</div>

I want to replace content synchronous each layer.  
I tried to this code

```auto
async function replaceContentsLoop(image, layerList) {
  try {
    await core.executeAsModal(() => {
      const result = action.batchPlay(
        layerList.map((layer) => {
          return {
            _obj: 'placedLayerReplaceContents',
            null: {
              _path: fs.createSessionToken(image),
              _kind: 'local',
            },
            layerID: layer._id,
            _options: {
              dialogOptions: 'dontDisplay',
            },
          };
        }),
        {
          synchronousExecution: true,
        },
      );

      console.log(result);
    });
  } catch (e) {
    console.log('replaceContents', e);
  }
}

```

And actionDescripton array is this

 ![스크린샷 2023-03-24 오후 6.10.56](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/3/36641d04ad6880eef2adbf4780c62c065ba41347.png)

But its working at same layer

 ![스크린샷 2023-03-24 오후 6.07.05](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/3/3c1dbdc89e97c02b722fd79a8826260d0846dad7.png)

how can i fix it ??

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [March 24, 2023, 10:47am UTC](https://forums.creativeclouddeveloper.com/t/batchplay-loop-synchronous-not-working/6078/2 "2023-03-24T10:47:43Z")

</div>

`layerID` is read-only information when you listen to the event. But when you execute the event it has no use and is ignored. You should select a layer before executing the action.

---

<div class="post-metadata">

**Author:** ![cintamani](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@cintamani](https://forums.creativeclouddeveloper.com/u/cintamani)\
**Post date:** [March 27, 2023, 5:17am UTC](https://forums.creativeclouddeveloper.com/t/batchplay-loop-synchronous-not-working/6078/3 "2023-03-27T05:17:40Z")

</div>

I can’t understand the meaning of “select a layer before executing the action” 🥺🥺  
Isn’t that code also selecting a layer before executing the action too ?

* * *

I SOLVED IT !!!
