get the Entity and Attribute names from the passed properties in a pluggable widget.

0
Hi developers,   I'm developing a pluggable widget that captures the screen then create and commits the image using the Mendix Client API 9. It works, but I currently need to statically enter the entity name as "MyFirstModule.Image" in the create API function. I want to dynamically pass the entity name to my component based on the developer's selection from the domain model.   mx.data.create({ entity: "MyFirstModule.Image", // <-- Static entity name // other parameters });
asked
1 answers
1

Hi Saif! 

 

If I understand you correctly, you want to give the developer the opportunity to select and pass the location of the entity that is used to store the image? Does this mean that the developer has access to the widget settings?

Because if so, you can add a string property in the widget XML that the developer can use to fill in the module-name, and one string property to fill in the entity-name.

These will show in the widget settings in Studio Pro.

 

Like this:

 

<property key="moduleName" type="string">

            <caption>Name of module</caption>

            <description>The exact name of the module.</description>

</property>

<property key="entityName" type="string">

            <caption>Name of entity</caption>

            <description>The exact name of the entity.</description>

</property>

 

Make sure that caps are set correctly, as this renders literally.

When you render your widget, you can use those properties to create a variable which represents the correct module and entity.

Like this:

 

moduleEntityName () {

 

        const { moduleName, entityName } = this.props;

        const combinedName = `${moduleName}.${entityName}`;

        return combinedName;

    };

 

Then use the combinedName in your mx.data.create function,

 

const customName  =  moduleEntityName();

mx.data.create({

        entity: customName;

// other parameters });

 

This way you can dynamically use different module- and entitynames in the same code.

 

If the developer should not able to configure the widget settings in Studio Pro, then you can use eventListeners and onclick-actions to perform the same logic based on for instance the dataview. This will be a bit more complex though.

 

Hope this helps! If you need assistance, please reach out!

 

Best regards, Stefan.

 

answered