4

Presently, a messagebox appears with the failing class name:

enter image description here

Is it possible to override the default behavior in Alfresco? Could we use forms service to present a different message ?

Luis Sánchez
  • 121
  • 1
  • 6

3 Answers3

5

Additional to zladuric answer,

you can use failureCallback method to show message what you want. But it is difficult to search failureCallback method of workflow forms for a new one because workflow forms such as "Start Workflow", "Task Edit", "Task Detail" are used form engine.

For example, in "Start Workflow" form, you can add our own successCallBack and failureCallBack by writing onBeforeFormRuntimeInit event handler in start-workflow.js like this.

 onBeforeFormRuntimeInit: function StartWorkflow_onBeforeFormRuntimeInit(layer, args)
          {
            var startWorkflowForm = Dom.get(this.generateId + "-form");
            Event.addListener(startWorkflowForm, "submit", this._submitInvoked, this);

            args[1].runtime.setAJAXSubmit(true,
             {
                successCallback:
                {
                   fn: this.onFormSubmitSuccess,
                   scope: this
                },
                failureCallback:
                {
                   fn: this.onFormSubmitFailure,
                   scope: this
                }
             });
          }

 onFormSubmitSuccess: function StartWorkflow_onFormSubmitSuccess(response)
      {
        this.navigateForward(true);
    // Show your success message or do something.
      }
onFormSubmitFailure: function StartWorkflow_onFormSubmitFailure(response)
      {
        var msgTitle = this.msg(this.options.failureMessageKey);
        var msgBody = this.msg(this.options.failureMessageKey);

        // example of showing processing response message
        // you can write your own logic
        if (response.json && response.json.message) 
        {
            if(response.json.message.indexOf("ConcurrencyFailureException") != -1) 
            {
                msgTitle = this.msg("message.concurrencyFailure");
                msgBody = this.msg("message.startedAgain");
            }
            else
                msgBody = response.json.message;
        }
        Alfresco.util.PopupManager.displayPrompt(
                {
                    title: msgTitle,
                    text: msgBody
                });
      }

Since Alfresco.component.StartWorkflow(in start-workflow.js) extends Alfresco.component.ShareFormManager(in alfresco.js). You can override onBeforeFormRuntimeInit event in start-workflow.js. I hope this your help you.

swemon
  • 5,840
  • 4
  • 32
  • 54
4

I'm not looking at the code right now, but this looks like a regular YUI dialog. So it's fired by YUI. So this YUI is client side, probably in My-tasks dashlet or my tasks page.

Furthermore, the error message looks like it is a status.message from the failed backend message/service.

You could probably locate that client-side javascript file, find the method that starts the task and see what its' failureCallback handler is. Then edit that failureCallback method and make it show something different then the response.status.message or whatever it is. Perhaps something like this.msg("message.my-custom-error-message"); which you then customize on your own.

Zlatko
  • 18,936
  • 14
  • 70
  • 123
  • Thank you, you bring me the hint. – Luis Sánchez Jan 25 '13 at 19:03
  • Just one more suggestion. You could probably find out which backend script is giving this error message. (Probably one of the workflow webscripts). Then edit the script to catch the error and to give back some meaningful status message. You don't have to touch the frontend that way. You can choose your way depending on what you're more comfortable with. – Zlatko Jan 25 '13 at 20:47
0

Modifying YUI dialog scripts will might affect the other functionalities as well. If we customize start-workflow. js, its only going to be achieved in start workflow form.

So as generic solution, below is the suggestion.

When alfresco is rendering the workflow form , it is rendering the transition button using the activiti-transition.js file.Basically this buttons are doing nothing more but submitting the workflow form.

So the best way would be , customizing this activiti-transition.ftl and activiti-transition.js file , to make an ajax call and handle the response as we want.

I just had a look on full flow of how this front end error is shown.

  1. activiti-transition is submiting the workflow form.
  2. Using a function named as submitForm which resides inside alfresco.js, it is invoking an submit event of form
  3. Inside the forms-runtime.js file there is one function named as _submitInvoked(handles the submit event of form), which is responsible for making an ajax call and submitting the workflow form.If there is error while submitting , it will display the error which is from backend.
Krutik Jayswal
  • 3,165
  • 1
  • 15
  • 38