Workflow: Prevent approval/submission if required metadata missing


(Tim Davison) #1

We are currently migrating from a Matrix v4.12 instance to a Matrix v5.1 instance.  We use EES/Edit+ for authoring and approvals in workflow.

 

One seemingly small difference between the way EES behaves between the two versions is that in v4.12 users could not submit or approve assets in workflow if any mandatory metadata was missing.  Instead the status drop-down on the details tab was disabled, a message saying metadata has not been filled in shown, and a link to the metadata screen.

 

In v5.1 there is no message and users are allowed to both submit and approve assets despite having empty mandatory metadata fields.  Assets get all the way through to the final phase in workflow in this way.  Then to add insult, a publisher (the last step in the workflow) is often unable to get locks on the metadata screen as the author (i.e. previous workflow users) still have EES open and currently have those locks.  Basically renders the asset stuck, requiring a SysAdmin to forcibly come in and yank the locks and make the updates.

 

My preference is for the behaviour from v4.12.  If there is any mandatory metadata missing the asset cannot be submitted/approved. until it is entered.  Is this possible?  Is there an option I need to set, either in the workflows themselves or in EES config, to get the old behaviour back?

 

Cheers


(Bart Banda) #2

My preference is for the behaviour from v4.12.  If there is any mandatory metadata missing the asset cannot be submitted/approved. until it is entered.  Is this possible?  Is there an option I need to set, either in the workflows themselves or in EES config, to get the old behaviour back?

 

Yea we relaxed that requirement a bit as we had multiple requests to allow for authors to put assets into workflow whilst still needing to populate some metadata fields, as some of those fields often had to/could be entered in by other approvers. 

 

We didn't add a configuration option for it either and haven't had the need to do so ever since the change went in, which I believe might be even older than Matrix 5.0. 

 

If you feel that such a feature/config option would be suitable you are welcome to submit an idea into the Roadmap project for further discussion and review. Or I can start a discussion for you if you'd like. 

 

You might be able to do it with an Edit+ custom plugin as a workaround in the meantime though, but I haven't created one like that before.


(Tim Davison) #3

Thanks Bart.  Thought it might be something like that.

 

In the meantime, if anyone else has similar issues (although sounds like we are the only ones using it like this) this is what I've come up with for an EES Plugin.  Add this to the EasyEditScreenLoad handler.

var config.options.mandatoryMetadata = ['My.Metadata.Field.Name'];

if (EasyEditScreens.currentScreenName == ‘Details’) {
EasyEditAssetManager.getCurrentAsset( function(asset) {
asset.metadataValues = null; // forces a refresh of the cached metadata values
asset.getMetadata( function(data) {
for (var i = 0; i < config.options.mandatoryMetadata.length; i++) {
if (!data[config.options.mandatoryMetadata.length[i]].length) {
$(’#ees_editStatus’).before($(’<div class=“ees-plugin-metadataRequired”><i class=“fa fa-exclamation-triangle”></i>This asset cannot be made live because some mandatory metadata fields are empty.</div>’));
break; // shortcircuit as soon as you have a failure
}
}
});
});
}

Oh yeah, and you may want to consider disabling the submit for approval and any similar option - I haven't got that far yet but it's something I'll be including.

 

Some notes about the above, in case some parts seem weird or pointless:

  • You can't use JSAPI in the usual way as EES is already using it.  Fortunately most JSAPI functions still seem available.  Unfortunately they are not readily apparent, they are abstracted and encapsulated in the EasyEdit framework.  To get the metadata you need to use the framework to get the asset first.  Additionally, calling the functions in the standard JSAPI way don't work, most notably some arguments are altered/not required.
  • The loop shortcircuits - I only wanted to display a single warning.  But you could easily add more HTML to say which fields were missing content.
  • You need to set asset.metadataValues to null as this field caches the values, so you'll be comparing old copies of the data rather than the most recent.  Most likely this is a performance tuning.  It seems to only refresh when you hit the metadata screen.  If you manually clear it then it forces the framework to get the latest copy.  Performance-wise this additional call is fast (only takes 170ms from work, 90ms at home).  Nevertheless I've restricted it to only on the Details screen (depending on author needs I may need to display a warning on the workflow screen as well, in which case I'll clear it for that screen as well).
  • The response from getMetadata returns field names and their corresponding values, not whether the the field is required or not.  By itself not enough to tell us when to show a warning.  See next point in how to configure.
  • config.options.mandatoryMetadata (not it's real name) is an array of strings, literally the metadata field names we are interested in.  This needs to be configured elsewhere in the plugin (shown in the first line in the example code above).  Add strings of the fieldnames you require filled in before submission - this will allow the flexibility of forcing fields you've specified filled in now, and other required fields able to be filled in later.  Also allows you to configure it different on site-by-site basis (at least the way I set up EES plugins it does).  
  • I've only catered for text fields at the moment.  Not sure how other field types, like multiple fields, selects, related assets, and especially dates, would work.  Text is enough for us at the moment, but I'd imagine if it needed to be expanded out you'd have to handle the different types somehow, possibly requiring additional configuration options.

Hope that all makes sense and helps someone (even though it seems we're the only ones who want this behaviour).