How to uniquely identify macros?

Hi,

I’m currently developing on an app which allows the user to create a Macro and serve some content on a given page. The macro collects data from users which must be stored in Active Objects.

Problem 1: How can I uniquely identify a macro? The macro-id is only unique for a page and the current version.

Solution 1: I could attach a unique id (macro parameter) which is generated by my app whenever a macro is inserted for the first time into a page.

Problem 2: If I use solution 1, I might run into a situation where a user copies a macro: To the same page, or to another page. If the user edits the data in a copied macro, they would change the data for all macros with the same macro parameter - as the macro parameter is not changed when copying.
Problem 3: If I cut and paste the macro to the same page, or to another one, I want to keep the reference to the data.

Maybe you have run into similar situations and have some advise. I’m looking for best practices if no solution exists.

To me this looks like you actually want to identify an entry in an ActiveObjects table and not so much a macro. (Which doesn’t necessarily mean you can’t use the macro ID for that)

Using a separate macro parameter to identify that table entry sounds like it would be the best solution.

Also, wanting to have “cut and paste” work but not “copy and paste” is not going to be easy. To implement something like that you would have to either check at macro insertion / page edit time whether a given ID already exists and then abort the page edit (or change the ID).

Maybe telling us a bit more about your actual use case could help us help you better. I feel like using page properties + a web-item that allows you to turn on a feature for the given page might be better than using a macro in your case (think something the “clone” or “delete” button, just for your feature) :slight_smile:

Cheers,
Sven

1 Like

That was already quite helpful. I’ve tried handling the cut and paste / copy and paste scenario with a listener on the paste event and change the I’d accordingly. However, this solution does not work reliably.

A pageproperties + webitem sounds great but will not work. Let me show an example:

I want to show certain content, e.g. images. A macro is a good representation because the user can embed the macro anywhere in the page. To display the image, the data must be loaded from the database.
It is unlikely that the user will have more than one instance of the macro on the page, but it is definitely a use case that should be supported.

Maybe just storing a generated id + page id and use both to identity the entry? Is this a reliable way or are there better solutions.

Hi @dennis.fischer , have you found a solution on the copy/paste and cut/paste scenario?

Hi @eagle.xiao ,

I have not found any good solutions. You’re always going to run into some kind of trade-off situation.

@dennis.fischer Hello, just wanted to ask how you managed to check for a macro paste event? Also, do you happen to remember why the solution was not reliable?

@JordanSpoonerdev