Conditional write to multiple data store entities

I have a situation like this with saving data to database:

- in employee update process user can change employee's personal and address data

- address is joined to employee via foreign key addressId on employee entity

- if address is not chosen from codebook it goes on approval to "address admin"

- id address admin approves new address it should be added to the codebook

- this means following: If user updated personal data and added new address (which is approved in the next step), data will be stored to employee table and to address codebook table. If user updated personal data and added existing address, only employee data should be stored to employee table.

How can I configure this conditional save using Write to Multiple Data Store Entities?

Am I allowed to use expression editor to configure IF statement? Is this statement below correct (if I assume I have process variable addressAddedFlag)?

if (pv!addressAddedFlag = true,

{{entity:cons!EEDM_EmployeeDataStoreEntity, data:pv!employee},{entity:cons!EEDM_AddressDataStoreEntity, data:pv!address}},

{{entity:cons!EEDM_EmployeeDataStoreEntity, data:pv!employee},{entity:cons!EEDM_AddressDataStoreEntity, data:{} }}

)

  Discussion posts and replies are publicly visible

Parents
  • Of course you're 'allowed' to write a condition to choose what your W2MDSE actually writes to the DB. A couple of things worth mentioning:

    1. you do not need to write if(pv!addressAddedFlag = true - assuming pv!addressAddedFlag is a Boolean you can simply write if(pv!addressAddedFlag  because it is either true or false - there's no need to compare it to the literal 'true'
    2. I would encourage you to encapsulate the expression as rule in its own right because you can test and maintain it independently from the process model you're using it in. It also means you can attach Unit Tests to the Expression and thus validate it still behaves as expected if/when you change it
    3. I believe your second write statement will either fail (if the address table has any non-null attributes) or write an empty row, which I suspect is not what you want - I think you could just leave out the address entity and only have it write the employee entity

    Hope this helps

  • +1
    Certified Lead Developer
    in reply to Stewart Burchell
    encapsulate the expression as rule in its own right

    And also, formatting won't be lost every time the input field is saved and closed (because for some reason it's never occurred to them that 1-line expressions are no longer sufficient under most circumstances Rolling eyes)

Reply Children
No Data