cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
mark6
Level: Powered On

Patch last record on CDS

Hi, my question is very simple, but I could not find anything helpful. I would like to patch the last record that has a blank field in my CDS entity. The scenario is this: I have several records with the same value in a field (let's say fieldA) and I want to write to an another field (fieldB) only on the most recent one. Consider that the field I mentioned are all the equals, what changes is the creation date. How can I achieve that? The Last function is not delegable, so it doesn't always do what I want (almost never). 

2 REPLIES 2
Super User
Super User

Re: Patch last record on CDS

Hi @mark6 

 

You can try using the formula:
Patch(DataSource, First(Sort(Filter(DataSource, Field1 = "<<ValueToMatch>>"),'Modified On',Descending)),{Field2:"<<valueToUpdate>>"})
Here, please replace DataSource with your actual Data Source name and you can get the last updated record, using OOTB attibute "Modified On".
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
mark6
Level: Powered On

Re: Patch last record on CDS

Hi  ,

thanks for your answer. I tried your formula but the behaviour is always the same. The strange thing is that on my computer it does work, but when I execute on my device (Samsung tablet) it doesn't work. In particular it patches another record, the first one, not the latest. I cannot figurate why. I inserted a Refresh(entity) before the operation but the problem still remains. Any other suggestion?