Confluence.saveMacro does not save macro body

The documentation on saveMacro accepts a macroBody parameter that suggests the macroBody will be updated if it is provided.

This does not work as expected and calling saveMacro with a macroBody does not actually update the body.

Example Code

AP.confluence.saveMacro({
    version: 1,
    name: 'test-macro'
}, "Test macro body");

I’ve tested this on both macros with an existing body, and macros with no existing body.

The macroParameters are saved correctly, but the macroBody is not.

There are no errors on the console either.

Not sure if I’m using the function wrong, any guidance would be appreciated.

Hi @JoeyL,

Which of the following methods do you use to bind your handler to the submission of the dialog:

  1. AP.events.on("dialog.submit", myHandler)
  2. AP.dialog.getButton("submit").bind(this.onDialogSubmit)

I think the second form is the way to go as the first method could result in timing issues.

Regards,
Dugald

Hi @dmorrow,

I was using the first method because I read somewhere that that was the preferred method.

I’ve just tried using the second method as you’ve suggested but the issue still persists.

I can see that a network request was made to save the Macro:

POST /wiki/rest/internal/1.0/macro/placeholder

And the new body is sent through in the request payload correctly.

But it just doesn’t get updated, leading me to believe it’s an issue with the actual Confluence API.

Hi @JoeyL,

I created a test for this and can get the macro data and macro body saved, but I do note one issue. My scenario is as follows:

  1. Visit a page with the dynamic content macro in it.
  2. Edit the page.
  3. Open the macro edit dialog.
  4. Make changes and click save.
  5. View the previewed version of the macro.
  6. Save the page.
  7. View the updated macro.

Step 5 observations:

  • New editor behaviour: At step 5, my macro does not reflect the updated data (neither macro data nor macro body). The macro view looks like it is refreshed, but it displays the old macro data. I’m using AP.confluence.getMacroData and AP.confluence.getMacroBody to retrieve the data in the macro view.
  • Old editor behaviour: At step 5, the macro reflects the updated data.

Step 7 observations: The macro reflects the updated data in both new and old editors.

My code for submitting the macro data is as follows:

AP.dialog.getButton("submit").bind(this.onDialogSubmit);
onDialogSubmit = (event) => {
    const dateTimeText = new Date().toString();
    const macroParams = {
      foo: `Bar - ${dateTimeText}`
    };
    const macroBody = `${dateTimeText}: Macro body`;
    AP.confluence.saveMacro(macroParams, macroBody);
    // No need to call AP.confluence.closeMacroEditor() if we return true.
    return true;
  }

How and when are you retrieving the macro data and concluding it’s not being updated?

Regards,
Dugald

Thanks for testing it @dmorrow.

After saving the macro and closing the dialog, I can see in the editor that the macro body stays the same (I’m using a rich-text body type).

Viewing the page in preview mode, I retrieve the macro data and body using AP.confluence.getMacroData and AP.confluence.getMacroBody. Using getMacroData returns the updated macro data, but getMacroBody returns the old macro body.

Saving/publishing the page also does not give me an updated macro body.

I copied your example to setup a simple test and can confirm that I am still having the same issue. Interestingly, using return true; does not work for me (wonder if that’s because we are using different versions of the JS API?). This is because I had AP.dialog.disableCloseOnSubmit();

For reference, below is how I setup a simple test:

On the Editor

const onDialogSubmit = (event) => {
        const dateTimeText = new Date().toString();
        const macroParams = {
          foo: `Bar - ${dateTimeText}`
        };
        const macroBody = `${dateTimeText}: Macro body`;
        console.log(macroBody);
        AP.confluence.saveMacro(macroParams, macroBody);

        AP.confluence.closeMacroEditor();
}

AP.dialog.disableCloseOnSubmit();
AP.dialog.getButton("submit").bind(onDialogSubmit);

On the view page

<script type="application/javascript">
    AP.confluence.getMacroBody(console.log);
</script>

Also, on another note:

I got this from the console logs:

DEPRECATED API - AP.dialog.getDialogButton().bind() has been deprecated since ACJS 5.0 and will be removed in a future release. Use AP.events.on("dialog.message", callback) instead.

Could there be a version mismatch between my setup and yours that’s causing the saveMacro to not behave as expected for me?

1 Like

Hi @JoeyL,

I had declared my macro body type as plain-text. When I change it to rich-text, I see the same behaviour as you - namely that the body appears empty, but the console shows it is<p />. Do you see any change of behaviour if you change your macro type to plain-text?

Regards,
Dugald

Hey @dmorrow,

I’ve changed my body type to plain-text and tested it.

I am seeing the same behaviour as you did including this:

So it looks like the problem is saveMacro does not update the body for rich-text body type. Is that the expected behaviour?

Changing the body type to plain-text also stops the macro body from being editable manually from the editor. What is the difference between plain-text and rich-text?

1 Like

Hi @JoeyL,

I don’t think it is expected behaviour. I chase this up with the Confluence team.

Regards,
Dugald

1 Like

Thanks @dmorrow for the help and effort you’ve spent on this!

In the meantime, the plain-text workaround is working for me. Hopefully we will be able to use rich-text soon.

1 Like

Hi @JoeyL,

I’ve created https://jira.atlassian.com/browse/CONFCLOUD-70237 to capture the issues we’ve observed.

Regards,
Dugald

1 Like

Could be related https://jira.atlassian.com/browse/CONFCLOUD-69962 ?