How to calculate an attribute based on previously made entries.

1
Hi there,   I want to create a document ID that should be calculated based on previous entries: - the first 3 character of a company name - an underscore - a 3 digit number    So with these entries: Company Name: Smith Number: 456 The attribute ID should be create like this Smi_456   I basically created an entity that holds strings for company name and number and should calculate the aforementioned ID attribute through a microflow.   I created that microflow and it creates a variable named calculatedID with one element only, a Creete String Variable with this formula:   substring($ContractData/SupplierName,1,3) + ‘_’ +  toString(number)   The thing is that mendix throws a super cryptic error message (frontend stupidly says to contact the admin, which is basically useless) 
asked
4 answers
0

Hey Philipp,

 

Are you sure $ContractData/SupplierName is filled and has more than 3 characters? If it is for example empty, then the substring-function will throw an error. So I would add an additional check that checks the following:
length($ContractData/SupplierName) >= 3 

If that's the case do you substring. If not… That's for you to decide :)

 

Hope this helps! 

answered
0

Hi Phillip,

First of all the log (if you're working on a cloud environment) or the console (if you're working locally) will contain more information on the error and will probably point you in the direction of what's wrong.

Secondly, if you want the first three characters, you'll need to change the substring to substring($ContractData/SupplierName,0,3), as the first character of a string is located at index 0.

 

Hope this helps.

Regards,

Luc

 

answered
0

Are the IDs supposed to be unique?

 

First of all, don’t use a calculated attribute for this purporse, use an After Create event. Othewise everytime you will use this ID your server will have a big amount of stuff to process before you have the response.

 

To resolve your question you could create an Autonumber support attribute that stats with “100” and concat this attribute with the first 3 company characters like this:

 

substring($ContractData/SupplierName,1,3) + ‘_’ + toString($ContractData/AutoNumberAttribute)

answered
0

Hi Philipp Kowalski,

 

I have answered for a similar question , you can check the below forum question for your reference.

https://forum.mendix.com/link/questions/106097 .

 

Hope it helps!!

If you are not able to solve it. I can you help you ATB!!

answered