How to update createdAt and updatedAt fields in your data type?

Hi, 

For best practice I have added a createdAt and updatedAt field in my CDT. This is generally good to have on several of my CDTs to trace activity in the future.

How do I save a date/time to these fields with system generated data at the time of form submission? What are the recommended solutions for something like this? 

Many thanks, 

Eric

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer
    One solution would be to have an "Update Audit Fields" node in your process model before your data write.

    Here, you could save "now()" into updatedAt. For createdAt, you could use the following logic to save to your createdAt field:

    if(
    isnull(CDT.createdAt),
    now(),
    CDT.createdAt
    )


    Otherwise, you could have the same logic built into the submission button on your form.

    Personally, I don't like having a lot of code on the submit button since it's not always an obvious place to check. Meanwhile, looking through process history makes it very clear what's happening in your process model. Thus, I would recommend the first solution.
Reply
  • +1
    Certified Lead Developer
    One solution would be to have an "Update Audit Fields" node in your process model before your data write.

    Here, you could save "now()" into updatedAt. For createdAt, you could use the following logic to save to your createdAt field:

    if(
    isnull(CDT.createdAt),
    now(),
    CDT.createdAt
    )


    Otherwise, you could have the same logic built into the submission button on your form.

    Personally, I don't like having a lot of code on the submit button since it's not always an obvious place to check. Meanwhile, looking through process history makes it very clear what's happening in your process model. Thus, I would recommend the first solution.
Children