Microflow to Add CurrentDate and the Name of the Publisher of a Comment

0
I am trying to create a Microflow so when a new Object from the Berichte Entity (should be a place for people to create a “post” like a newsfeed basically) is created so that the Date of the Bericht and the Name of the person who wrote the Bericht will be added automatically when the person clicks Save. I have been toying around for quite some time now. I THINK I know that I need to Change the “NewBericht” (I think I need to reference the change to the new object I am trying to create) to [%CurrentDateTime%]. To add the Name of the Person who is writing the Bericht I THINK I need to Retrieve by association as the Name of the Members of the App are in a different Entity and I need to get this into the scope so I can use it. So I retrieve the Mitglied (Member) association to be able to use the name. The problem here is that I do not actually know how to make it so the name is always the current person trying to create a new post.   Now with the Microflow I have added to this post I can click on Create and I can make a post… I enter a Title for the Post and the actual Content of the Post but when I click on Save the Date is saved correctly but only when I click on Create a second time meaning the most up to date comment always has no date saved (you can see this in the upcoming picture) the Name is always empty. The next time I click on Create I get a new object with exactly the same content as the object I created before and then after I change the content it saves correctly but let us say I wanted to click Cancel then I just already have a new object which is the same as the last object created. The Name is still always empty. When I click Cancel the first time of any session the Cancel button actually works correctly.   Maybe someone knows more about Microflow than me and can help me out.
asked
3 answers
0

The most easy and best option is to go to your domain, to entity Berichte and tick the two checkboxes ‘createdDate’  and ‘owner’. This will automatically add the creation date and the creator as soon as the new Berichte gets initiated.

Later, when you want to show those attributes, you can just call them Berichte/createdDate and Berichte/own

If you want to still show the name of person, even after it is deleted (like Eline correctly mentions), you can also redundantly copy the Mitglied’s name to a Berichte-attribute (MitgliedName for instance). You can do this adding a AfterCreate microflow (see the tab EventHandlers in the properties of the entity) so this is done upon creation of the Berichte without you having to complicate the save-microflow.

Beware: the AfterCreate-Eventhandler for entity Berichte also get executed if you create a Berichte any other way.

And by the way: you need no ‘NewBerichte’.

answered
0

Alright, so first things first – is your entity “Mitglied” a specialization of “Account”? If so, you will be able to get to it via $currentUser (with inheritance splits and casts).

I see that you're opening a page before you create your “Berichte”. I would recommend only opening the page after creating the “Berichte” (without commit) so you can pass the NewBerichte to that page and show it there, including the fields where the user can enter the message. This also means that a cancel button will actually get rid of the created object.

So your microflow for the “Create” button would look something like this:

- Cast the currentuser to get your Mitglied

- Create a new Berichte and change some attributes (e.g. the association to Mitglied, or a string with the user's username in it that stays even when an account is deleted and the currentdatetime)

- Open a page where the Berichte is shown

Here, the user can enter their data.

Now, all you need is the standard save and cancel buttons, and those should delete or commit the Berichte as needed.

answered
0

Now my entity “Mitglied” is a specialization of “Account” if I did it correctly. I will have to read up on inheritance splits and casts again though since this is a pretty complicated topic at the moment in my opinion.

I did try to follow along with the instructions you gave me Eline but these are functions I have not used yet so it is taking me a little while but I think I understood the general idea of it.

At the moment my Microflow looks like this because I decided to do it from scratch and follow your steps. From my understanding, I have to insert an Object Type Decision to be able to cast anything. Now I have to read up so I figure out how to be able to cast currentuser to get my Mitglied. I hope I am not completely off topic? We have learned about this stuff already at our university lectures a little but this is going a bit deeper than our lectures.

answered