Setting a default Attribute value of an entity

0
Hello there, I'm new to Mendix and doing some experimentation with my first Application - a simple HelpDesk Request management system. The idea being that a user opens a page to create a new request.  Fills out some data - username, phone number etc. and a new request is created.  So far so good.  Aside from storing details of the Request in various tables, I also have a table which stores the possible Status a request may have - New, In Progress, Completed and so on.  Obviously, I want new logged Requests to be created with the Status of New. I couldn't find a way to set the Entity Selector to do this for me by default, to avoid the user from having to select the New option.  Is this true - can this not be done via the form directly? Next I tried creating a Microflow, to override the standard Save button on the form.  On the form is an invisible Entity Selector for the RequestStatus So my actions are: Retrieve RequestStatus from the form via the Association (a null value at this stage, as the user hasn't selected a value) Change Object - update RequestStatus(StatusName) to 'New' Commit the new Request Object to the database Close the form   The Microflow fails at runtime with the error: com.mendix.modules.microflowengine.MicroflowException: requirement failed: Change object 'RequestStatus' should not be null at RequestManagement.SaveNewRequest (Change : 'Change 'RequestStatus' (StatusName)')   So I seem to be stuck, as I can't seem to update the Status without it being set first, which is exactly what I was hoping I would be able to do from the form! It seems like such a simple thing and I'm sure there are lots of ways to achieve this. Any ideas for me? Many thanks, David.    
asked
4 answers
2

To resolve the error, you will need to create a request status object instead of updating it...since you can't update and empty object.  So use a Create action instead of the Change action, set the status to New and set the association to the request object so you can retrieve it as needed.  If you know the request status is empty, no need to retrieve it.

Hope that helps.

 

***Edit***

I created this domain model:

I then created a simple microflow which receives a Request object as a parameter and creates a new RequestStatus object.  See screen shot below:

The yellow highlighted member sets the Association between the new RequestStatus and the Request.

Let me know if you have any other questions.

answered
1

Can you set a default value for the attribute Status?

 

go to your domain model. Click the attribute and at the bottom you can set a default value. 

answered
0

I thought I'd cracked this but I was too hasty.

This is the order of my Microflow:

  • Create String variable to contain the new status
  • Create a new RequestStatus Object, giving the Status name the value in the String variable
  • Change the Requests Object (from the form) so that it's Status name is equal to the newly Created RequestStatus Object
  • Commit the Requests Object
  • Close the form

 

The problem is - this is adding new (duplicate) status's to my Status table.  Not the desired behaviour.  I've also tried Deleting the new Status name object before the commit is made, but this means that the Status for the main Request object is not stored.

Any help would be gratefully received!

 

answered
0

Hi David,

  It sounds like you have an entirely separate entity called requestStatus that you use to hold the status of the request.  What you should do is create an attribute on your Request object named 'requestStatus' and have it be an enumaration (link). Create a new Enumeration called requestStatus with the three values (New, in Progress, Completed) and then set New as the default value for your attribute.  Enumerations give you lots of power to drive data retrieves, filtering, and page layouts.  It also and ensures that you don't end up with a host of 'requestStatus' entities that fill up a table with duplicates.  Enumerations is the best-practice way to accomplish what you want.

  So to complete your use case, you should:

1) Create an attribute on your Request object of type 'Enumeration'. Call it requestStatus

2) Create a new Enumeration called requestStatus that contains your three desired values.  Link your requestStatus attribute to this enumeration.

3) Set the default value for the requestStatus attribute to be 'New'

Now when you create a new request, the status should already be set and you don't have to mess around with a separate entity or a string and things will be much cleaner.

Let me know if this makes sense or if I should add some pictures.

answered