# Perspective - Creating a custom event on component

**URL:** <https://forum.inductiveautomation.com/t/perspective-creating-a-custom-event-on-component/33700>\
**Category:** Module Development\
**Created:** [April 6, 2020, 2:27am UTC](https://forum.inductiveautomation.com/t/perspective-creating-a-custom-event-on-component/33700 "2020-04-06T02:27:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dillonu](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@dillonu](https://forum.inductiveautomation.com/u/dillonu)\
**Post date:** [April 6, 2020, 2:27am UTC](https://forum.inductiveautomation.com/t/perspective-creating-a-custom-event-on-component/33700/1 "2020-04-06T02:27:34Z")

</div>

Is there an example of how to create a custom event on a custom perspective component?

I’ve been trying to follow another thread on how to do this:  
[http://forum.inductiveautomation.com/t/creating-a-component-event/30403/2](http://forum.inductiveautomation.com/t/creating-a-component-event/30403/2)  
However, the JsonSchema class fails to parse the example in the following post, which causes my module to fail to load:  
[http://forum.inductiveautomation.com/t/creating-a-component-event/30403/9](http://forum.inductiveautomation.com/t/creating-a-component-event/30403/9)

I’m running on Ignition 8.0.10, fresh install.  
I’ve moved the `events` key out to a separate json file, which the `JsonSchema.parse` fails to load:

```auto
{
    "type": "object",
    "events": [
        {
            "name": "onCustomClick",
            "description": "This event is fired when a Component is clicked.",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "description": "The name of the component."
                    }
                }
            }
        }
    ]
}

```

 ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/34b50ef4492629426d40e89cfe3699e0322160c8.png)  
This is the code setting up the component:

```auto
package org.example.common.component.display;

import java.util.List;

import com.inductiveautomation.ignition.common.jsonschema.JsonSchema;
import com.inductiveautomation.perspective.common.api.ComponentDescriptor;
import com.inductiveautomation.perspective.common.api.ComponentDescriptorImpl;
import com.inductiveautomation.perspective.common.api.ComponentEventDescriptor;
import org.example.common.RadComponents;

public class RadManager {
    public static String COMPONENT_ID = "example.controller.manager";
    public static JsonSchema SCHEMA = JsonSchema.parse(RadComponents.class.getResourceAsStream("/radmanager.props.json"));
    public static JsonSchema EVENT_SCHEMA = JsonSchema.parse(RadComponents.class.getResourceAsStream("/radmanager.event.json")); // Line that causes the error

    public static ComponentEventDescriptor EVENT_DESCRIPTOR = new ComponentEventDescriptor("onCustomClick", EVENT_SCHEMA);

    public static ComponentDescriptor DESCRIPTOR = ComponentDescriptorImpl.ComponentBuilder.newBuilder()
        .withPaletteCategory(RadComponents.COMPONENT_CATEGORY)
        .withPaletteDescription("A component to holding custom events.")
        .withId(COMPONENT_ID)
        .withModuleId(RadComponents.MODULE_ID)
        .withSchema(SCHEMA) // this could alternatively be created purely in Java if desired
        .withPaletteName("Rad Manager")
        .withDefaultMetaName("radManager")
        .withEvents(List.of(EVENT_DESCRIPTOR))
        .shouldAddToPalette(true)
        .withResources(RadComponents.BROWSER_RESOURCES)
        .build();
}

```

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 6, 2020, 2:44am UTC](https://forum.inductiveautomation.com/t/perspective-creating-a-custom-event-on-component/33700/2 "2020-04-06T02:44:05Z")

</div>

I think the error you’re seeing is suggesting that `RadComponents.class.getResourceAsStream("/radmanager.event.json")` is returning `null`, which probably means the file is either not packaged in your module or is in the wrong location.

---

<div class="post-metadata">

**Author:** ![dillonu](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@dillonu](https://forum.inductiveautomation.com/u/dillonu)\
**Post date:** [April 6, 2020, 3:27am UTC](https://forum.inductiveautomation.com/t/perspective-creating-a-custom-event-on-component/33700/3 "2020-04-06T03:27:39Z")

</div>

You’re right, I physically called it `/radmanager.event.json`.  
After fixing that and reloading the module, I now get the following when a script on the event runs:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/0ed6cac9eb45a2e0bdb225a8a4a3254adf1a52aa.png)

I invoke the event via:  
`that.props.componentEvents.fireComponentEvent("onCustomClick", { name: "test123" });`

I can see the custom event now on the component, and the script I added to the event is:

```auto
def runAction(self, event):
	"""
	Method that will run whenever the selected event fires.

	Arguments:
		self: A reference to the component that is invoking this function.
		event: An empty event object.
	"""
	system.perspective.print("Hello World")

```

So what might `EDGE_SCRIPT_BYPASS` refer to? I’m running on a demo version of the full Ignition (not edge).

Thanks.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 6, 2020, 3:32am UTC](https://forum.inductiveautomation.com/t/perspective-creating-a-custom-event-on-component/33700/4 "2020-04-06T03:32:12Z")

</div>

You said you’re on a fresh 8.0.10 install, but you can verify that and verify that your modules are all 8.0.10?

This error suggests you’re not, as mentioned by Paul in this post: [Perspective Component Script Actions not working (Ignition 8.0.9)](http://forum.inductiveautomation.com/t/perspective-component-script-actions-not-working-ignition-8-0-9/33396/9?u=kevin.herron)

---

<div class="post-metadata">

**Author:** ![dillonu](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@dillonu](https://forum.inductiveautomation.com/u/dillonu)\
**Post date:** [April 6, 2020, 4:00am UTC](https://forum.inductiveautomation.com/t/perspective-creating-a-custom-event-on-component/33700/5 "2020-04-06T04:00:41Z")

</div>

My bad, I used the 8.0.9 installer (I’m developing across too many machines). This was a fresh install though. Haven’t messed with the base modules.  
I’ve now uninstalled, deleted the leftover Ignition files, and installed 8.0.10.

Seems to work now, thanks!

Side question - why doesn’t the argument for the event show up on the generated comments?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/0ba8fea8aa9cde02a8fbea25050444544058f0cb.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 6, 2020, 3:13pm UTC](https://forum.inductiveautomation.com/t/perspective-creating-a-custom-event-on-component/33700/6 "2020-04-06T15:13:21Z")

</div>

Loading a schema as JSON isn't _quite_ sufficient to parse the extra details of the context (for reasons I'm not sure of, we have an internal method that does the whole process from a JSON file, but don't expose it.  
As a third party author, you need to make your own event descriptor(s) for as many custom events as you want to add. You can either create the JsonSchema manually in code, or use the same parsing methodology. Just take every object inside your `events` array and (for simplicity) move them into their own files. Then load these resources as well as your main component schema, and register your event descriptors. I added more detail to the previous thread you referenced with the solution to that OP's issue.

> [@Creating a component event](http://forum.inductiveautomation.com/t/creating-a-component-event/30403/16):
>
> For posterity; posting the solution to the issue with the script editor: As I vaguely alluded to, you're not able to (unfortunately) get the automatic parsing of schemas out of a single file that we use internally - which means that the main issue with your module at present is the single event object schema being supplied for all four component event descriptors. So, to start off, you'll want to move them into separate files, and also flatten them - you don't need separate name, description (…
