M.R.
M.R.

Reputation: 4827

Sitecore custom item validator

I need to make a custom item validator that checks on workflow final state about the language versions that exist for the particular item. I know I am supposed to inherit Sitecore.Data.Validators.StandardValidator, or Sitecore.Data.Validators.ItemValidators.WorkFlowFinalStateValidator, but what are the methods that are available to me on this? Is there a way I can find this out?

Update: I created a custom validator using the StandardValidator class, and implementing the ValidatorResult method. I then registered this class in the system/settings/validation rules section. I then set the standard values fields for an item and this works in the regular Quick Bar validation rules, and the validation bar. I am able to see the error.

Now I want to use this in the workflow actions rules. What do I need to do? I chose the new rule to set it in the workflow rules area in the standard values section of the item, but when I execute the command in the workflow, it just doesn't run... what am I missing?

Upvotes: 1

Views: 1719

Answers (1)

Jay S
Jay S

Reputation: 7994

Our team works with StandardValidator as the base for any field validation we are doing, such as writing an AlphanumericValidator that will ensure a text field value is, well, alpha-numeric.

I'm not sure what you are intending to do with the language versions, but I know we were running some workflow actions to check if an Item had a version in another language to inform the user of the current state of translation. When an Approve action took place in a certain step, prior to final, we added a workflow action to kick off our code. Rather than using a validator, we actually implemented and registered an event handler. It looked something like this:

public void Process(WorkflowPipelineArgs args)
{
    Item dataItemCurrentLanguage = args.DataItem;
    Item dataItemOtherLanguage = GetItemInOtherLanguage(dataItemCurrentLanguage);

    if (dataItemOtherLanguage != null && dataItemOtherLanguage.Versions.Count > 0)
    {
        //Insert what you want to check for here
        if(isGood)
        {
            //Do something
        }
        else
        {
            Context.ClientPage.ClientResponse.Alert("Something bad!");
            args.AbortPipeline();
        }
    }
}

Upvotes: 3

Related Questions