Custom Publish Trigger - set metadata values
Hi,
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.
dynamicMetadata[i].setValue("0");
}
}
Let me know if I can provide any more information,
Thanks!
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | 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
1 Posted by Ryan Griffith on 18 Apr, 2016 03:02 PM
Hi,
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.
Thanks!
2 Posted by ces55739 on 18 Apr, 2016 03:14 PM
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 Posted by Ryan Griffith on 18 Apr, 2016 05:34 PM
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:
Please let me know if you have any questions.
Thanks!
4 Posted by ces55739 on 18 Apr, 2016 05:47 PM
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 Posted by Ryan Griffith on 18 Apr, 2016 06:06 PM
My apologies for the confusion. Based on the following I assumed you wanted to email a group when a specific user published a page:
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.
Thanks!
6 Posted by ces55739 on 18 Apr, 2016 06:11 PM
Thanks for the help!
I was hoping to avoid using Web Services, but I will go ahead with it.
ces55739 closed this discussion on 18 Apr, 2016 06:11 PM.