Hi community,

Calling a Business process is quite easy in FreedomUI, by adding a button and choosing

Action: Run process.

The problem with this approach is that once the button is clicked, there is no validation happening in the page.

Is there any code snippet or workaround that when clicking a button that runs a business process, prior to the calling of the process a validation(practically a Save) happens?

Sasori

Like 1

Like

6 comments

The only option currently is to wire up code for the button. It would first save the page, then if the save was successful you would execute the process. 

See how to save the page and detect if it was successful here: https://customerfx.com/article/saving-a-page-before-some-action-on-a-creatio-freedom-ui-page/

See how to start the process via code here: https://customerfx.com/article/starting-a-process-from-client-side-code-on-a-creatio-freedom-ui-page/

Ryan

Ryan Farley,

Thanks for the response Ryan. Do you actually have an example on how to integrate within the 'CustomMethod' both crt.SaveRecordRequest and crt.RunBusinessProcessRequest ?

Ryan Farley,

Ryan if im not mistaken, with the suggested approach , every time the user will click the SAVE button, the overriden crt.SaveRecordRequest will be called?

In the first linked example, you would only be running that `usr.CustomCodeRequest` handler when you click your custom button. If you put the code inside the crt.SaveRecordRequest handler, then it would be run every time the user saved the page in some way.

Sasori Oshigaki,

As Harvey mentioned, the code for your button will only execute when the button is clicked, not when the Save is clicked. Your button will also initiate a save and then, if successful and validated (and the save occurred) it will then execute the process. The code from the first article triggers the save to happen and then provides the result. In the article (the first one) the save returns a result, where the code has // save was successful, continue with something else here you'd replace that with the code to start the process (the second article). If needed, you can see how to wire up custom code to your button in this article: https://customerfx.com/article/adding-a-button-to-execute-custom-code-on-a-creatio-freedom-ui-page/

Ryan

Thank you  both Ryan and Harvey! Was able to achieve what i intended!

     {
    request: "so.SaveAndRunBP",
    handler: async (request, next) => {
            const saveRecordRequest = {
            type: "crt.SaveRecordRequest",
            preventCardClose: true,
            $context: request.$context
        };
        if ((await request.$context.executeRequest(saveRecordRequest)))
        {
          const handlerChain = sdk.HandlerChainService.instance;
          const result = await handlerChain.process({
              type: "crt.RunBusinessProcessRequest",
              processName: "SoGenerateContact",
              processParameters: {
                  ContactId: await request.$context.Id,
              },
              $context: request.$context
          });
        }
        return next?.handle(request);
    }
}
Show all comments