Skip to main content

Notifications

Power Apps - Microsoft Dataverse
Answered

Save date of deactivation in custom CDS entity

(0) ShareShare
ReportReport
Posted on by 593

Dear all,
I have a custom entity of which I want to track when each record was being deactivated.

What would be the best way to do this? Probably an Power Automate flow, but I don't really see what steps it should consist of...

thanks,

Koen

Categories:
  • KoJaPD Profile Picture
    KoJaPD 593 on at
    Re: Save date of deactivation in custom CDS entity

    A little update: I ended up adding a "CloseDate" field, which is set by the end-user; A flow will then check every day for all records with a CloseDate and deactivates it...

  • Verified answer
    EricRegnier Profile Picture
    EricRegnier 8,705 on at
    Re: Save date of deactivation in custom CDS entity

    Hi @KoenJanssensPD,

    Yes,, if it needs to automatically close (deactivate) a record in the future, the simplest would be a close date filed with a schedule Power Automate flow that run daily which deactivates the records. Check that the record is not already closed and doesn't have a date before setting the date though. I would try to keep it as simple as possible, but a user can also deactivate so as I mentioned in my 1st post, have either a sync or another flow to set the close date if the record was closed by a user. 

    Hope this clarifies....

  • Re: Save date of deactivation in custom CDS entity

    so maybe I'm oversimplifying things, but since a deactivated record is inactive and cannot be modified, can you just get a list of inactive records with modified on date? That should tell you when records were deactivated.

     

    Yes, I know that if you really want to you can update inactive records (I wrote tip of the day 254 after all) but this almost never happens. sometimes the simple solution is the best.

  • KoJaPD Profile Picture
    KoJaPD 593 on at
    Re: Save date of deactivation in custom CDS entity

    Thanks everybody for your thoughts!

    To explain a bit the business case: records are created when needed, and deactivated when not needed anymore (and will not be needed in the future) except for BI purposes. We need to know when and how many records where active in the past .

    Should I better add a "close" date on the entity? And a flow that automatically deactivates the record when a record is closed?

     

    Thanks,

    Koen

  • EricRegnier Profile Picture
    EricRegnier 8,705 on at
    Re: Save date of deactivation in custom CDS entity

    To supplement on the previous and my post, there are different schools of thought, but I suggest not to rely on the Modified On date, the record can be updated after it's deactivated (i.e. integration or background jobs) which will auto-update the Modified On date. 

    I assume the deactivate action happens by the user so a record can be reactivated after it's deactivated, so you might want to clear the deactivated date afterwards. And if a record cannot be reactivated then you can hide the Reactivate ribbon/command bar button with the Ribbon Workbench.

    You also can enable audit history on that entity and field, which can remove the need of a custom entity and simplify your solution. 

    Cheers

  • David Jennaway Profile Picture
    David Jennaway 716 on at
    Re: Save date of deactivation in custom CDS entity

    One issue to consider is that, once a record is inactive, you can't update it, so you can't simply add a field to the custom entity for the deactivation date, and set it via an asynchronous workflow (either Power Automate, or classic and asynchronous). There are 3 options, in my order of preference:

    1. Use a synchronous (classic) workflow that runs on the Before stage, which updates the field on the custom entity
    2. You could just use the modifiedon field. Once a record is inactive, it can't be changed, so the modifiedon is necessarily the date of the last change, which was the deactivation 
    3. Store the deactivation date in a child entity of the custom entity, then use any workflow type to create this. An advantage of this is you'd have a history of every time the record is deactivated, if this is useful

    For completeness, you could have an asynchronous workflow that reactivates the record to set the field, then deactivates it again, but you'd also have to avoid getting in a loop

  • EricRegnier Profile Picture
    EricRegnier 8,705 on at
    Re: Save date of deactivation in custom CDS entity

    Hi @KoenJanssensPD,

    yes a Power Automate flow would be the preferred approach however it will run asynchronously so users won’t see the deactivated date right away. Make sure you create the flow within a solution and use the “Common Data Service (current environment)” connector: https://docs.microsoft.com/en-us/power-automate/connection-cds-native

    The trigger is update of the entity and you can filter only when the statecode field is updated and when the value of statecode  = 0


    The other way if you need a synchronous process is with classic workflows: https://docs.microsoft.com/en-us/power-automate/workflow-processes

     

    hope this helps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,508

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,839

Leaderboard

Featured topics