Custom Publish Trigger - set metadata values

ces55739's Avatar


18 Apr, 2016 02:09 PM


I am working on creating a publish trigger to set the value of the asset being published (this is a workaround, so it is a bit nasty). In this example, the metadata field is a radio button with two possible values, 0 or 1. I want to be able to set the value to 0 whenever it goes through the publish trigger. Please see the code snippet and the attached log file. Why is this error occurring?

DynamicMetadataField[] dynamicMetadata = page.getMetadata().getDynamicFields();
String content = null;
DynamicMetadataField tinkerEditsField = null;
// loop over every dynamic metadata field
for( int i = 0; i < dynamicMetadata.length; i++ ){
       // if field is the "Tinker Edits" field
       if( dynamicMetadata[i].getLabel().equals("Tinker Edits")){
                // I have verified that the content gotten here is being retrieved correctly (content = "1")
        content = dynamicMetadata[i].getValues()[0];
                // ERROR: When I try to setValue, it seems to fail.

Let me know if I can provide any more information,

  1. 1 Posted by Ryan Griffith on 18 Apr, 2016 03:02 PM

    Ryan Griffith's Avatar


    Calling a setter on an object in this situation won't work, so you may need to rework things a bit.

    I am assuming this is a follow up to your recent discussion. When you have a moment, please provide some context for what you are trying to accomplish and attach your Publish Trigger code so we can take a closer look.


  2. 2 Posted by ces55739 on 18 Apr, 2016 03:14 PM

    ces55739's Avatar

    Thanks for the reply Ryan

    We need to email our web authors whenever a publish from a specific user goes through, but only for those users. In the discussion you mentioned we tried to email our web authors based on whoever last published the page.

    In this case, I tried to set a hidden metadata value to 1 whenever a user submits an Event. Then when the asset is published, the custom publish trigger emails the author if that value is 1. Then set the value to 0. If the value is 0, then don't email.

    Let me know if you need any more information. Sorry this is still in a testing state.

  3. 3 Posted by Ryan Griffith on 18 Apr, 2016 05:34 PM

    Ryan Griffith's Avatar

    Thank you for the additional information.

    Let me loop in our Services team to see if they have any suggestions for you.

    In the meantime, I was wondering if the following would work:

    Use an automated Edit Workflow that simply publishes the asset and is only applicable to that user's group. This Workflow would essentially send an email to your web authors group and publish whenever the user edits the page. Such a Workflow would look something like:

    <system-workflow-definition name="Email and Publish on Edit" initial-step="save-and-publish">
          <trigger name="email" class="com.cms.workflow.function.EmailProvider" />
          <trigger name="merge" class="com.cms.workflow.function.Merge" />
          <trigger name="publish" class="com.cms.workflow.function.Publisher" />
          <trigger name="version" class="com.cms.workflow.function.Version"/>
          <step identifier="initialize" label="Initialization" type="system">
                <action identifier="save-and-publish" label="Save and publish" move="forward" type="auto">
                   <trigger name="merge" />
                 <trigger name="version" />
                     <trigger name="publish" />
                 <trigger name="email">
          <step identifier="finished" label="Finished" type="system" />

    Please let me know if you have any questions.


  4. 4 Posted by ces55739 on 18 Apr, 2016 05:47 PM

    ces55739's Avatar

    Ah. That was the original idea. However, correct me if I am wrong, that would email a group if someone made an edit to a page using that workflow.

    We need a more dynamic solution: we need an email to only go out to the author of the page.

  5. 5 Posted by Ryan Griffith on 18 Apr, 2016 06:06 PM

    Ryan Griffith's Avatar

    My apologies for the confusion. Based on the following I assumed you wanted to email a group when a specific user published a page:

    We need to email our web authors whenever a publish from a specific user goes through, but only for those users.

    You are correct, though. This setup would require the user to Edit in order to start the automated Workflow. That being said, they can simply Edit+Submit without needing to make changes.

    Looking back at the Publish Trigger option, there is a known defect in which the Edit operation checks to make sure the asset is not persisted before making an update. The issue is the Read operation returns a persisted asset, so it's impossible to edit the asset. I've attached the defect to this discussion so you can track its progress in the upper right-hand corner.

    As a workaround, the best thing I can think of would be to use Web Services along side of your plugin. This could be done by either compiling and using Web Services within the plugin itself or calling an external script that uses Web Services.

    Please let me know if you have any questions.


  6. 6 Posted by ces55739 on 18 Apr, 2016 06:11 PM

    ces55739's Avatar

    Thanks for the help!

    I was hoping to avoid using Web Services, but I will go ahead with it.

  7. ces55739 closed this discussion on 18 Apr, 2016 06:11 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac