I think that there is a fundamental flaw with the TextToEntityRefText function, or I do not understand it. I have a Text variable which contains a reference to an entity (my "JOB" entity). It has to be a Text variable, because it is coming from NotifyWidgetGetMessage. Now, I need to be able to look up an entity with this value, so I am running a query and using the value TextToEntityRefText(NotifyWidgetGetMessage()) for the parameter. According to the docs, this should do the trick. Unfortunately, the TextToEntityRefText function gives me a generic EntityReference type, but the query's parameter is strongly typed to "JOB Identifier".

So, if I have a Text value that represents my entity reference, how do I look up that reference?



What is the problem exactly?

Imho, it is the correct way, and it just does a reflect to the correct identifier.

Does it give an error?

Joost -

The problem is that TextToEntityRefText gives a type of "EntityReference". This is a useless type because throughout the entire system, entity references are more strongly typed. For example, in my JOB entity, if I have a query with the condition of: "JOB.Id = JobId" where "JobId" is a parameter with type "JOB Identifier", when I set the parameter equal to "TextToEntityRefText(NotifyWidgetGetMessage())" it says there is an error because I am trying to use type "EntityReference" where type "JOB Identifier" is expected.

Hi Justin,

I believe that "TextToEntityRefText(NotifyWidgetGetMessage())" would work if your entity had a text key field.
Try using this instead: IntegerToEntityRefInteger(TextToInteger(NotifyWidgetGetMessage()))


Paulo -

That fixed it, thanks! I'll send a bug report to have the error message made more clear.

Is there a fixfor this problem? I am experiencing the same issue but using IntegerToEntityRefInteger doesn't work for me. I am trying to look up a record in a static entity. The identifier is fetched from the response of a rest API and is text. When using the solution Paulo mentions i get an internal error...

I am using Service studio

Besides an very old thread. it should work.
However, with static entities you have to be sure the Id really exists.
especially when you use Get<entity>(id)

Hi J. 

Only thread i could find about this subject. The id does exist, the problem seems to be the cast from text to integer, it always returns 0. I worked around it by creating a function to do a lookup in the static entity based on the textual value. You would expect the build-in function TextToEntityRefText to work but it still doesn't, that is why i brought it up. Still the same issue that Justin described. After TextToEntityRef it expects a more strongly typed identifier and won't compile.

texttointeger does not work?

I am working with that plenty of time without a problem.

strange, what is the text?

can you provide a sample oml?


I tested it quickly and it works fine..
attached is the oml I have created.
screenshots are showing the results...
it's nothing fancy..

see screenshots

and with a basic text

Hi J,

I see why for me TextToInteger doesn't do the job. I only have textual keys like 'rustig' of 'druk' and they all translate to 0 when using TextToInteger.
The function TextToEntityRefText does work standalone but when used to access a record in a static entity it expects a stronger typed identifier. Instead of a regular Entity Identifier it requires a 'Name-Of-Entity'Identifier. In my case the entity is named BusyText so the Data Type for the Id is BusyText Identifier and so the types don't match.
Not sure what you getting at, but TextToEntityRefText works fine as well ::

I used it exactly like this and in my situation i can't publish because of a mismatch in DataTypes for the identifier. Very strange! I will try to throw an example together this weekend.
As a reference, in Version 9:

TextToEntityRefText is now named TextToIdentifier
IntegerToEntityRefInteger is now IntegerToIdentifier

This saved me some time and confusion, thanks!  - IntegerToEntityRefInteger(TextToInteger(NotifyWidgetGetMessage()))