How to launch flow action or view in a modal in Constellation application : A custom approach

This document captures the steps required to launch flow action or view in modal dialog in Constellation application, this is a custom dx component approach.

Note: Before using this approach, hope explored all possible ways to solve this usecase using OOTB configuration.

Editing data object

In order to do update on data objects, do follow the below article:

You can replace Operator class with any other data class, infrastructure remains the same.

https://support.pega.com/discussion/how-update-operator-profile-or-data-constellation-application-using-savable-datapage

Reading data object via flow action

Steps:

  1. Open app studio and create and configure a view eq., UpdateDetailsAction1

  1. Switch to Dev studio and create a flow action under data object class and configure above View eq., UpdateDetailsAction1.

  1. Create a single page type datapage, this is used to build context (step page) to execute flowaction/view.

  1. Write a custom component to launch modal.

References**:**

Sample gallery: https://github.com/pegasystems/constellation-ui-gallery

Builder: https://docs.pega.com/bundle/constellation-sdk/page/constellation-sdks/sdks/creating-custom-components.html

Sample code

import { Button, Modal, useModalManager, useModalContext } from '@pega/cosmos-react-core';

export default function ViewInModal(props) {
  const { getPConnect } = props;
  const pConnect = getPConnect();

  const { create } = useModalManager();
  const { dismiss } = useModalContext();

  const onResponse = async (data) => {
    const { fetchViewResources, updateViewResources } = PCore.getViewResources();

    // Update metadata store
    await updateViewResources(data);

    // Update redux with data.
    pConnect.updateState(data.data);

    // Root view
    const viewName = data.uiResources.root.config.name;

    // Build config to create new pconnect object
    const viewConfig = {
      meta: fetchViewResources(viewName, getPConnect()),
      options: {
        context: getPConnect().getContextName(),
        pageReference: 'dataInfo.content',
        isFlowContainer: '',
        parentPageReference: ''
      }
    };
    const { getPConnect: newPConnect } = PCore.createPConnect(viewConfig);

    // Create view component.
    const viewElement = newPConnect().createComponent(viewConfig.meta);

    // Model rendering
    const modal = () => {
      return (
        <Modal heading='List of cases' autoWidth enter>
          {viewElement}
        </Modal>
      );
    };
    create(modal, { closeInitialModal: dismiss }, { dismissible: true });
  };

  const itemClick = () => {
    // Get row prop value
    const id = getPConnect().getValue('.ID');

    // Rest api to open flow action, define single datapage type under "data_view_ID" payload
    // to load the record before processing, this will become context to view.
    // action_ID is the flow action name.
    // Pass parameters as part of body.
    PCore.getRestClient()
      .invokeRestApi('openDataObjectAction', {
        queryPayload: {
          data_view_ID: 'D_TestData',
          action_ID: 'TestFA'
        },
        body: { dataViewParameters: { ID: id } }
      }, getPConnect().getContextName())
      .then((data) => {
        onResponse(data.data);
      });
  };
  return (
    

```
<Button variant='link' icon compact={false} onClick={itemClick}>
      Modal
    </Button>
```

  );
}

Code explaination

  1. Add custom dx component to view.

Reference: https://github.com/pegasystems/constellation-ui-gallery

OR

In case custom component required to be part of ListView table then do follow below article:

https://support.pega.com/discussion/how-add-custom-dx-component-listview-table-constellation-application

@baipcI am trying to use the above code, and I can see errors. Some of the functions require few mandatory parameters to be passed. How did you bypass these?

fetchViewResources - requires ClassID

createComponent - requires data source and additional properties

invokeRestApi - missing context

Thanks Acquil

@baipc To call a Flow Action or Local Action, Can we use the Pcore API method openLocalAction ?

@baipc

In the code, “openDataObjectAction” means an API that should be built according to out requirement right?

@baipc

Thanks for posting on this topic. As per your suggestion, I’m trying to create a component and using the above mentioned code. But I’m getting error on calling API createComponent that all the required data source and additional properties are not passed. As you mentioned in the previous comment, I tried passing as empty object but still error persists. PFB the screenshot of the same.

It will be really helpful if you could share the right snytax or arugments for the createComponent to be called in the context.

@baipcI’m able to launch the flow action and see the view in a modal window but flow action buttons are not available. I believe this approach can be followed to show a readonly data using a data page context. But I can’t do any action apart from close. PFB the screenshot of the same.

@Connect@Abicom

@ghosa4 Is it possible to show button?

@baipc

Thank you for the solution. It worked for the data class. When I created the flow action and the view in the data class, and used it as the step you mentioned, I was able to open the flow action.

Can you please let us know if we have any solution to keep my flow action and view in the work class instead of the data class?

@Acquil All required information can be accessed through pConnect APIs,

For classID: pConnect.getValue(“.classID”)

createComponent: pass as empty object.

invokeRestApi: pConnect.getContextName()

@baipc Thanks for your reply.

I am able to fix the compilation issues but now when I publish the component, below error is seen, even though the module is present in my workspace. Can you please suggest a fix for this? any update to be done to tsconfig.json?

Error… Can’t resolve ‘@pega/pcore-pconnect-typedefs/rest-client’ in ‘*********\src\components\Ee_Extensions_LaunchAction’

@SameeraS openDataObjectAction is OOTB action, it takes flowaction id as a parameter so you can do custom logic in flowaction.

@Rajashekar Reddy CH You can use if context is a casetype, for datatype it will not work.

@SameeraS Behind the scene triggers rest/dxapi eq., /data/D_Savable/action/{flowaction}

@Connect@Abicom Kindly try using the following syntax:

const viewElement = newPConnect().createComponent(viewConfig.meta, "", 0, {});

We will also address this in the upcoming release to make these arguments optional.

@ghosa4 @baipc I really appreciate your quick help. I’m able to use the shared syntax and launch the flow action of a data type successfully in the Pega Constellation portal.

Also, please note that I was getting undefined error for props and data params passed to the function as part of the component code which I fixed by defining it as type any as mentioned below. Hope this is the right way of fixing the error.

i.e. const onResponse = async (data**:any**)
export default function ViewInModal(props**:any**)

@baipc - Any chance this would be included as OOTB Pega component in next releases? We are trying to avoid creating Custom components.

@Sandeep_Ghosh We are working on different experience/approach to address this kind of usecase, in future releases you will see better/best OOTB.

@baipc

Can you please guide me understand more about “openDataObjectAction”. What did you mean by OOTB Action?

@Connect@Abicom This is typescript error, please ignore.
@ghosa4 How to disable it?

@baipc @ghosa4
Thanks for the prompt response. What do you meant by ignore. Despite this compile time error, I tried publishing the component now but it fails while generating the build. PFB the screenshot of the same. I’m unable to test this component within Pega portal due to this issue.

Assistance on this solving this issue will be really helpful and greatly appreciated.