close

Filter

loading table of contents...

Studio Developer Manual / Version 2304

Table Of Contents

9.26.3.2 Running Workflow Form Extension

The Global Link Translation Workflow defines several extra fields for a running workflow form as shown in figure Figure 9.11, “Start Workflow form Extension for a Running Global Link Translation Workflow” (note that the "Due Date" field is an input field here for the sake of the example, it is normally a read-only field for a running Global Link workflow).

Start Workflow form Extension for a Running Global Link Translation Workflow

Figure 9.11. Start Workflow form Extension for a Running Global Link Translation Workflow


The following code gives the complete definition of the running workflow form extension for the the Global Link Translation Workflow. The details are explained afterwards.

          
import { workflowPlugins } from "@coremedia/studio-client.workflow-plugin-models/WorkflowPluginRegistry";
import { Binding, DateTimeField } from "@coremedia/studio-client.workflow-plugin-models/CustomWorkflowApi";
import Gcc_properties from "./Gcc_properties";

interface GccViewModel {
  globalLinkPdSubmissionIds?: string;
  globalLinkSubmissionStatus?: string;
  submissionStatusHidden?: boolean;
  globalLinkDueDate?: Date;
  globalLinkDueCalendar?: Calendar;
  globalLinkDueDateText?: string;
  completedLocales?: string;
  completedLocalesTooltip?: string;
  xliffResultDownloadNotAvailable?: boolean;
}

workflowPlugins._.addTranslationWorkflowPlugin<GccViewModel>({

  workflowName: "TranslationGlobalLink",

  nextStepVariable: "translationAction",

  startWorkflowFormExtension: {...},

  runningWorkflowFormExtension: {
    computeTaskFromProcess: ProcessUtil.getCurrentTask,
    computeViewModel(state: WorkflowState): GccViewModel {
      return {
        globalLinkPdSubmissionIds: transformSubmissionId(state.process.getProperties().get("globalLinkPdSubmissionIds")),
        globalLinkSubmissionStatus: transformSubmissionStatus(state.process.getProperties().get("globalLinkSubmissionStatus")),
        globalLinkDueDate: dateToDate(state.process.getProperties().get("globalLinkDueDate")),
        completedLocales: convertLocales(state.process.getProperties().get("completedLocales")),
        completedLocalesTooltip: createQuickTipText(state.process.getProperties().get("completedLocales"), localesService),
        xliffResultDownloadNotAvailable: downloadNotAvailable(state.task),
      };
    },

    saveViewModel(viewModel: GccViewModel) {
      return {
        globalLinkDueDate: viewModel.globalLinkDueDate,
      }
    },

    fields: [
      TextField({
        label: Gcc_properties.TranslationGlobalLink_submission_id_key,
        value: Binding("globalLinkPdSubmissionIds"),
        readonly: true,
      }),
      TextField({
        label: Gcc_properties.TranslationGlobalLink_submission_status_key,
        value: Binding("globalLinkSubmissionStatus"),
        readonly: true,
      }),
      DateField({
        label: Gcc_properties.TranslationGlobalLink_submission_dueDate_key,
        value: Binding("globalLinkDueDate")
      }),
      TextField({
        label: Gcc_properties.TranslationGlobalLink_completed_Locales,
        readonly: true,
        value: Binding("completedLocales"),
        tooltip: Binding("completedLocalesTooltip"),
      }),
      Button({
        label: Gcc_properties.translationResultXliff_Label_Button_text,
        value: Gcc_properties.translationResultXliff_Button_text,
        validationState: "error",
        handler: (state): GccViewModel | void => downloadXliff(state.task),
        hidden: Binding("xliffResultDownloadNotAvailable"),
      }),
    ]
  },

  ...
})
        

Example 9.107. Running workflow form extension for Global Link Translation Workflow


To customize the running workflow form for a custom workflow, the parameter WorkflowPlugin#runningWorkflowFormExtension<M> is used. The view model is the same as for the startWorkflowFormExtension. The parameters are also very similar to those of the previous section:

computeTaskFromProcess?: (process: Process) => Task;

An optional function to compute the current task from a given process. Its purpose is described under the following point.

computeViewModel(state: WorkflowState): M

A function that computes the view model for the extension's fields. Contrary to the StartWorkflowFormExtension#computeViewModel() function it receives a WorkflowState parameter. It has the two properties WorkflowState#process (a Process remote bean) and WorkflowState#task (a Task remote bean) which hold the currently displayed process and task respectively.

Note that the process property is always given and that the bean is fully loaded. For the task property, things are a bit more complicated. It is set if either (1) the workflow form displays a task (e.g. opened from "Inbox") or (2) the workflow form displays a process (e.g. opened from "Running") but RunningWorkflowFormExtension#computeTaskFromProcess() from above is given. Otherwise task is set to null.

Note that the function computeTaskFromProcess is wrapped in a dependency-tracked FunctionValueExpression under the hood. Thus, it may return undefined as long as the current task cannot be computed due to asynchronous sub-computations. The surrounding framework ensures that RunningWorkflowFormExtension#computeViewModel(state: WorkflowState) will always be called with a WorkflowState parameter where the process and task remote bean properties are set and fully loaded (with the one exception from above where task is null).

In the example, several view model properties are computed based on the current WorkflowState. While some computations are just access calls to the process variables, others require more complex computations and utilize helper functions.

saveViewModel(viewModel: M): Record<string, any>

Contrary to StartWorkflowFormExtension#saveViewModel() function, this function to save the view model changes back to the process is not only called once (upon workflow start) but whenever the view model changes.

fields

An array of the running form extension's fields. The same explanations as for StartWorkflowFormExtension#fields apply here. The example shows a mixture of field properties that are directly set or bound to a view model property.

remotelyValidatedViewModelFields?: (keyof M)[]

The same explanations as for StartWorkflowFormExtension#remotelyValidatedViewModelFields apply here.

viewModelValidator?: (viewModel: M) => WorkflowSetIssues

The same explanations as for StartWorkflowFormExtension#viewModelValidator apply here.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.