Advanced Workflow Step

Mohamad Ramadan asked on September 15, 2020 13:29

Hi,

I have the current scenario

  • I have a custom table called "Representative Type", loaded with predefined data as a lookup
  • and I have advanced workflow with a step called "Send To Representative" i need to enable the user to select the representative type before taking the action "Send To representative"

how to implement this scenario i can add a new field on the page and display this field on the page type, but this is not user friendly and not all pages will be sent to the representative as well

is there a way to enable the user to select the representative after choosing to send to representative action on an advanced workflow step, I need the user to be able to select a value from a dropdown menu (loads it's data from predefined custom Table) so

Recent Answers


Dmitry Bastron answered on September 15, 2020 16:02

Hi Mohamad,

I don't think that the customization you are asking for is possible to implement on 100%. The closest you can get to I think could be one of these solutions:

  • to use a user choice or automatic choice and manage the list of representatives as choices
  • write a custom workflow step that will be reading a representative field from page type (like you mentioned in your question)
0 votesVote for this answer Mark as a Correct answer

Mohamad Ramadan answered on September 15, 2020 16:33

Hi Dmitry

thanks for the reply, the list of representative types is unknown to me, the client can add one or many types later as he works, so I think the first option is not gonna help by anyway, am I right?

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on September 15, 2020 17:22

Yes, the first option is not applicable then. Regarding the second option, you can try the following workaround: for your page type field you can add visibility condition:

EditedObject.DocumentWorkflowStep.CodeName = "YourWorkflowStep"

When the admin will move the document to this step - this field will appear only then. However, making it required maybe a bit more difficult to do. If you simply mark the field as "required" it will not help as it doesn't stop you from moving document between workflow steps. It will require writing some global event handler, but I'm not 100% sure it will work in this particular case.

1 votesVote for this answer Mark as a Correct answer

Mohamad Ramadan answered on September 17, 2020 11:06 (last edited on September 17, 2020 11:08)

Hi Dmitry

I applied the second option where a page type now have the representative type as a drop-down list

I'm facing an issue now, where I need to ensure the editor user select a representative before choosing "send to a representative ", the editor user has other options like publish directly so not all documents need to be sent to a representative

I've tried to use the global workflow event Approve_After to cancel and throw an exception with a custom message but this doesn't help "a general error message is displayed and the document I think it's moving to the next step, then after the refresh, it return back to the editor step"

so how can I implement this, even if from another event like document.saveafter to force the user to select the representative and display a custom error message

https://imgur.com/nJtH7C5

Image Text

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on September 17, 2020 11:14

Hi Mohamad,

You'd need to do it inside before event (Document Update Before, or Workflow Approve Before). If you cancel in Before event, the actual action will be cancelled, in After event it's too late, the CMS has already written these changes in the database and can't un-do it.

0 votesVote for this answer Mark as a Correct answer

Mohamad Ramadan answered on September 17, 2020 12:32

ok great one last thing how to show a custom message like "please choose representative" on the info bar or as an exception on red, if you have an example or reference would be great

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on September 17, 2020 12:42

I believe this code should do the trick:

eventArgs.Cancel();
throw new Exception("Your custom error message");
0 votesVote for this answer Mark as a Correct answer

Mohamad Ramadan answered on September 21, 2020 10:48 (last edited on September 21, 2020 10:48)

Hi Dmitry

What I’ve try but is not optimal and didn’t fulfill my requiring

  1. add condition on the choice “Send To Representative” The condition is
    (!string.IsNullOrEmpty(Document.RepresentativeType)) && (Document.RepresentativeType.NotEquals("-1"))

This hide the choice from the menu, until representative is selected but I need it to be disabled not hided

2.Try to use the Workflow Event Approve.Before

          if (e.PreviousStep.StepName == "Representative")
            {
                e.Cancel();
                throw new ApplicationException("select representative frist");
     }

This fire exception after the action is clicked, and a message informs that workflow is moved to representative step, with general error message “to see the log details”, I’ve to refresh the page to see it’s still on the same editor process and workflow not moved

How to solve this issue,

I need a way to either disable the button not hide it Alternatively, display a custom message if the representative not selected

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on September 21, 2020 11:46 (last edited on September 21, 2020 11:47)

Hi Mohamad,

  1. If you want to disable it, simply move your condition in the page type configuration from Visibility condition to Enabled condition, then it will disable your control rather than hide it.
  2. I've just tried the following example code and it prevents the user to publish the page until Representative field is filled with value.

Here is the code:

[assembly: RegisterModule(typeof(CustomInitializationModule))]
public class CustomInitializationModule : Module
{
    public CustomInitializationModule()
        : base("CustomInit")
    {
    }

    protected override void OnInit()
    {
        base.OnInit();

        WorkflowEvents.Approve.Before += Approve_Before;  // Note it should be "Before"
    }

    private void Approve_Before(object sender, WorkflowEventArgs e)
    {
        if (e.Document.WorkflowStep.StepName == "Representative" &&  // Check we are currently at Representative step
            e.Document.ClassName == "your.page.type.codename" &&
            string.IsNullOrWhiteSpace(ValidationHelper.GetString(e.Document.GetValue("Representative"), string.Empty)))
        {
            e.Cancel();
            throw new Exception("Your custom error message");
        }
    }
}

This is as far as you can get in customization. Apparently, you can't display your custom message here or disable the button. The exception message will only appear in the event log. It's not that customizable and you will need to educate your admin users to check this field I guess.

0 votesVote for this answer Mark as a Correct answer

Mohamad Ramadan answered on September 21, 2020 16:29

I think you didn't get my scenario well

  • the editor step type is "multi-user choice step", the editor user has other options like publish or send to cheif editor or send to reprsetative
  • the editor user with the editor role is the one who can make the choice to send to representative
  • so the current workflow for the document would be Editor step, not representative
  • so e.Document.WorkflowStep.StepName will equal Editor, not Representative
  • I've try to use (e.PreviousStep.StepName == "Representative") but previous step is null on Approve_Before
  • the e.PreviousStep is not null on the approved after
0 votesVote for this answer Mark as a Correct answer

Mohamad Ramadan answered on September 21, 2020 16:37 (last edited on September 21, 2020 16:40)

so I need to check the choose the editor user made on Approve_Before on the Editor Step, is there a way to do this as the user has multi-choices

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on September 21, 2020 18:49

Well, yes, in your case it needs to be checked in After event then because in Before event you cannot get in code what user choice was chosen (at least I haven't found how this could be done). Unfortunately, I don't see any other options on how to customize it further to meet your requirements.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.