0 votes

Process Paie_Docu

asked in Efficy/ Client side by (112 points)

2 Answers

0 votes

Hello dcousew,

With DB workflow, it should be pretty easy to achieve this result. I see you already made the total field readonly, that's perfect.

I can't see the entity being edited, so I named it Xxxx. I assume it's a custom entity.

This should be the skeleton of the workflow code:

function BeforeCommitXxxx(editId, inserted) {
  calculatePaymentTotals(editId);
}

function calculatePaymentTotals(editId) {
  var ds = Efficy.getMasterDataSet(editId, 0),
    dsXxxxDocu = Efficy.getDetailDataSet(editId, ntDocu),
    total = 0;

  dsXxxxDocu.first;
  while (!dsXxxxDocu.eof) {
    total += dsXxxxDocu.fieldByName("F_PAYMENT").asFloat;
    dsXxxxDocu.next;
  }

  ds.edit;
  ds.fieldByName("F_PAYMENT_TOTALS").asFloat = total;
}
answered by (7.4k points)
Thank you for this.
But it's quite the same as AfterCommitXxxx ?
The "F_PAYMENT_TOTALS" is updated only after saving the entity but not after saving  the changes of the amount in the "F_PAYMENT" field of the detail relation.

Dimitri
There is no event available for when an detail gets updated. Actually, the commit in DB happens together just after BeforeCommit of the edited entity, Xxxx.

When you are updating fields in the master dataset, always use BeforeCommit and not AfterCommit. Last one requires an extra Commit and this will slow down.
FYI, this guide https://help.efficy.com/edn/projectguides/workflow_events gives you a ServerJS module that allows you to trace all fired workflow events. You could simulate it in Efficy and see in the log the trace of all workflow events that were fired
0 votes

Hello Dimitri,

As you understood, you cannot use a workflow event, because there are none.

It does not mean that the changes you've made in the relation windows aren't stored somewhere. And that you cannot access them.

What you can do is :

  • On a custom "editView", in the start function, make an asynchronous call to a serverJS, with just the editHandle in parameters
  • In your serverJS, you can detect if a change was made in the detail Dataset with Efficy.detailModified(editHandle, TEntityHandle). You just have to use the EditHandle you sent as parameter.
  • If no change was made, then return, there is no calculation to do
  • Otherwise, calculate the new value and return it.
  • In the callback function of your serverJS call, just update the value.

And that's it. And don't worry, the solution is not "overkill". It is juste a small call to the back-end to check if the field need to be updated.

You could also, try to find a "client side" solution, were you store the value of the new field in the relation and you send this value to the parent window but backend is the only one you can trust :)

Regards,

Loïc

answered by (531 points)
1,249 questions
1,518 answers
1,858 comments
328 users