REST call produces multiple identical entries

0
Hi, I have created a rest call (get) which is invoked with a button through a microflow. The rest call works and stores the results in a persistent entity. So far so good, but the problem begins when executing the microflow, which starts the rest call, for a second time or more because the rest call produces the same entries over and over again: I have started the rest call microflow four times now, and all entries have been repeatedly stored.   The objects that are created via the rest call have an attribute called ‘PublicatieId’ that is unique for each object, and I think I need to check whether this unique attribute 'PublicatieId’ is already present, and if it is present not to create a new object with that particular ‘PublicatieId’ and continue with next object and so on.    The problem is that I'm quite new in Mendix and I don't know how I can fix this. I would like to have some help to solve this problem. Any help is greatly appreciated, thank you!   Edit: I've tried to solve this today, but I’m quite stuck. Any help would be really welcome.
asked
5 answers
0

Hi Suat,

An option in your import mapping is to find the object by Key. Go to the top of your import mapping, open the object and set the options with suit your purpose:

answered
0

Hi Suat, could you please mark my answer as the correct one so everyone knows your (initial) problem is solved.

For your second issue you would have to use the return list of objects which is returned by the call.  Add the attribute URL to the entity and in an iterator/loop,  set this attribute with ‘https://www.tenderned.nl/tenderned-tap/aankondigingen/’ + $ObjectName/PublicatieId’  as value. Then commit the list of objects.

answered
0

There are several approaches you could take.

The quickest, laziest, and dirtiest way is to retrieve and delete all previous entries before you make your call to the REST service. This may not be ideal if you associate the results to any other entities as those associations will be lost.

Another approach is retrieve and check you have data before making the call. If you have data and you are sure it won’t change, you may be able to just return what you have retrieved instead of calling the REST service.

If you can give us more details on the service you are calling, we may be able to suggest a better way.

answered
0

Hi Robert,

I'm still new to Mendix and I’m learning and working on the Mendix Free Cloud, and I really appreciate that you are helping me out. It is perhaps indeed best if I give you a detailed background and I will try to keep it as brief as possible.

I have created a rest call (get) which is invoked with a button through a microflow (screenshot of microflow included below).

The rest call retrieves a dataset that is a collection of published tenders in the last 24 hours for the time being, but this period will change to the last 120 hours once I get a working proof-of-concept.

The problem is that the users will retrieve the latest published dataset by starting the rest call microflow, because the data might have changed, or another user might have taken over.

The published tenders that are retrieved via the rest call are saved by an import mapping in an entity with four attributes; PublicatieId with type Integer which is an unique id-number for each tender, AanbestedingNaam with type String which is a description of the tender, AanbestedendeDienstNaam with type String which is the name of the party that issued the tender, and the fourth attribute is Europees with type Boolean which says whether the tender is a European tender or not (there is a legal difference between those two and an Euopean tender needs to be handled in a specific  protocol).

A data grid presents the entity named ‘Tenders’ where these tenders are stored, to the user in my app in order for them to decide whether a tender is interesting enough to explore further or not. Each tender will be weighed in this way, and the interesting tenders that will be qualified to be explored further, will be copied or cloned (I’m not sure how to this part yet) to another entity that is named ‘Bids’.

The qualification is dependent on the tenders so deleting the tenders and replacing them with new tenders is probably not the way to go, since the weighing whether to be qualified or not will also be lost with that.

I have two problems I would like to solve;

  1. The biggest problem is that I don’t know how to make some sort of check of the ApiCall dataset against the (unique) PublicatieId attribute in the entity ‘Tenders’,  and only write objects with unique PublicatieId that are not yet already present in the entity ‘Tenders’.
  2. A smaller problem that I don't know exactly how to copy or clone the interesting Tenders that are objects in the entity ‘Tenders’  to another entity that is named ‘Bids’. I will probably need an extra attribute with type Boolean in the entity ‘Tenders’, but I don’t know how to proceed from this point forward to copy or clone the object to another entity ‘Bids’.
answered
0

Hi Sjors, wow that did the trick!

Thank you for your help, I really appreciate it.

I did have one more question though:

One of the attributes I retreive via the restCall is ‘PublicationId’ and I need to use the value of this attribute to construct a URL that I would like to save in the same entity ‘Tenders’ in a new attribute called ‘TenderLink’.

The URL should be like this (of course [PublicatieId] should be swapped with the actual value of ‘PublicatieId’)

https://www.tenderned.nl/tenderned-tap/aankondigingen/[PublicatieId]

I don't really know how to do this though; do you perhaps have an idea how I could solve this problem?

answered