cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to properly refresh Object Page data when it's affected by req.on succeeded of draftActivation?

epamtiosteel
Explorer
0 Kudos
189

Hi colleagues

I'm trying to implement next scenario:

I have 2 Node.js apps working with a same data. First app hosts a service to input data (let's call it Contracts). Second app is performing (re)calculations for the Contracts on demand.

I want to trigger re-calculation when I successfully activate the draft so in the input app I'm using

async onAfterContractActicate(res: Contract, req: any): Promise<void> {
        const ID: Contract["ID"] = req.data.ID;

        req.on('succeeded', async () => {
            const srv = await cds.connect.to('ExternalCalculatorService');
            await srv.post(`/Contracts(ID=${ID},IsActiveEntity=true)/calculate`, {});
        });
    }

so the desired logic is:

  1. draft is saved
  2. draft activation triggered - request started
  3. transaction started
  4. active entity is being created / updated
  5. transaction is committed
  6. external re-calculation for the Contract is being called
  7. awaiting external re-calculation - it should return re-calculated Contract
  8. reply with the re-calculated contract

The issue is that the succeeded event is triggered after the response is being prepared and finalised so it's too late to change res or trigger req.reply as it's simply ignored.

The question is - how to get re-calculated data to the object page without weird FE extensions?
I tried

Common.SideEffects #ContractDraftActivated: {
TriggerAction: 'SiteService.draftActivate'
}
but obviously it's not a solution.

 

Accepted Solutions (0)

Answers (0)