# Batch play - play action firing on plugin reload but not when button is clicked

**URL:** <https://forums.creativeclouddeveloper.com/t/batch-play-play-action-firing-on-plugin-reload-but-not-when-button-is-clicked/4428>\
**Category:** UXP Plugin API\
**Tags:** javascript\
**Created:** [March 15, 2022, 5:38pm UTC](https://forums.creativeclouddeveloper.com/t/batch-play-play-action-firing-on-plugin-reload-but-not-when-button-is-clicked/4428 "2022-03-15T17:38:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mherb204](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/mherb204/32/2042_2.png) [@mherb204](https://forums.creativeclouddeveloper.com/u/mherb204)\
**Post date:** [March 15, 2022, 5:38pm UTC](https://forums.creativeclouddeveloper.com/t/batch-play-play-action-firing-on-plugin-reload-but-not-when-button-is-clicked/4428/1 "2022-03-15T17:38:17Z")

</div>

I’m attempting to map my actions to buttons in my UXP plugin. When setting the button to run the patch play function on-click it doesn’t work. However, when I reload the plugin it registers a click and runs the function. I’m brand new at UXP and only started learning Javascript to create a plugin for my company. Anyone that can help with a more comprehensive explanation would be my hero.

```auto
document
.getElementById("play-action")
.addEventListener("click", playAction('Wine Glass LASER'));

async function playAction(actionName){
const batchPlay = require("photoshop").action.batchPlay;
console.log("playing?")
const result = await batchPlay(
[
   {
      _obj: "play",
      _target: [
         {
            _ref: "action",
            _name: actionName
         },
         {
            _ref: "actionSet",
            _name: "Mockup Maker"
         }
      ],
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "wait"
});
}

```

---

<div class="post-metadata">

**Author:** ![AnthonyK](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@AnthonyK](https://forums.creativeclouddeveloper.com/u/AnthonyK)\
**Post date:** [March 15, 2022, 7:50pm UTC](https://forums.creativeclouddeveloper.com/t/batch-play-play-action-firing-on-plugin-reload-but-not-when-button-is-clicked/4428/2 "2022-03-15T19:50:18Z")

</div>

No JS expert either, but I think you might need different syntax to pass a variable to a “click” function:

```auto
.addEventListener('click', function() {playAction('Wine Glass LASER');});

```

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [March 15, 2022, 8:01pm UTC](https://forums.creativeclouddeveloper.com/t/batch-play-play-action-firing-on-plugin-reload-but-not-when-button-is-clicked/4428/3 "2022-03-15T20:01:33Z")

</div>

> [@mherb204](#):
>
> `.addEventListener("click", playAction('Wine Glass LASER'));`

Change to:  
`.addEventListener("click", function() {playAction('Wine Glass LASER')});`

_Edit_  
While replied on phone, you got your answer already 🙂

---

<div class="post-metadata">

**Author:** ![mherb204](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/mherb204/32/2042_2.png) [@mherb204](https://forums.creativeclouddeveloper.com/u/mherb204)\
**Post date:** [March 15, 2022, 8:05pm UTC](https://forums.creativeclouddeveloper.com/t/batch-play-play-action-firing-on-plugin-reload-but-not-when-button-is-clicked/4428/4 "2022-03-15T20:05:54Z")

</div>

Thank you both! One incredibly frustrating issue down. 500 to go!

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [March 15, 2022, 8:49pm UTC](https://forums.creativeclouddeveloper.com/t/batch-play-play-action-firing-on-plugin-reload-but-not-when-button-is-clicked/4428/5 "2022-03-15T20:49:35Z")

</div>

If you’re OK w/ modern JS syntax and want something shorter, this’ll do the same thing:

```auto
.addEventListener("click", () => playAction("Wine Glass LASER"));

```

---

<div class="post-metadata">

**Author:** ![mherb204](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/mherb204/32/2042_2.png) [@mherb204](https://forums.creativeclouddeveloper.com/u/mherb204)\
**Post date:** [March 16, 2022, 2:34am UTC](https://forums.creativeclouddeveloper.com/t/batch-play-play-action-firing-on-plugin-reload-but-not-when-button-is-clicked/4428/6 "2022-03-16T02:34:27Z")

</div>

I’m far too new to have any preference. I sincerely appreciate the help. We have a team of 8 working in photoshop daily and the time we all waste on repetitive tasks is crazy. The time it’s been taking me to learn Java and UXP will be saved in man hours in one week!
