cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Save date of deactivation in custom CDS entity

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

1 ACCEPTED SOLUTION

Accepted Solutions

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....

View solution in original post

7 REPLIES 7
Super User II
Super User II

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

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

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

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

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.

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....

View solution in original post

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...

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Users online (26,579)