47
Views
4
Comments
[Human Readable Change History] GetFirstTextAttribute returning the last text attribute
Question
human-readable-change-history
Web icon
Forge asset by Johan den Ouden
Application Type
Traditional Web, Reactive

Hi,

When looking for the text attribute of the entity in the SQL GetFirstTextAttribute, it returns a list of text attributes. Following which, we assign the output as GetFirstTextAttribute.List.Current.Query_EntityAttr.Name. As a result, this returns the last record of the list (instead of the first which we need). Therefore, I propose to include TOP 1 in the SQL. 

SELECT TOP 1 {Entity_Attr}.[Name],{Entity_Attr}.[Type] 
FROM  {Entity_Attr}
WHERE {Entity_Attr}.[Entity_Id] = @EntityId 
AND {Entity_Attr}.[Is_Active] = 1
AND {Entity_Attr}.[Name] not in (@PossibleNamesList )
AND {Entity_Attr}.[Type] = 'rtText'
ORDER BY {Entity_Attr}.[Order_Num] ASC
UserImage.jpg
nicksgg

Anybody have the same issue?

I have encountered the same issue but it is happening randomly. It is about 97% getting the correct reference value from a specific table. 

I have overcome using the site properties - IdentificationEntityAttributes_Exceptions. I am just wondering why there is such a randomness as the query (in GetFirstTextAttribute) without "TOP 1" above, it should be returning the first rtText type but it is returning the last rtText for the same query. 

2019-11-12 17-31-26
Justin James
 
MVP

Because there is no guarantee that .Current will be the first result if there is more than one, unless you are iterating over a result set and it is the first iteration. While obscure and a bit counter intuitive, this is known behavior of OutSystems and apparently it doesn't qualify as a "bug". I understand why it works like this under the hood and could explain it if I really needed to, but let it be enough to say that you should never depend on .Current representing a particular position in a list unless you happen to be iterating over it, or if you know there are 0 records (it will be empty) or 1 record.

J.Ja

2022-04-14 17-45-24
Paulo Cabral

A simple way to solve the problem is to open the DiffEntityDataToText module in your environment and put the value 1 in the Max. Records advanced query property, until the problem is fixed by the component developers and we can update it in our environment. 

Below is a screenshot of the correction:  

2019-11-12 17-31-26
Justin James
 
MVP

Really wish some of this had been worded differently/better... the way this was phrased, it wasn't clear that this was not just a question... I've made the change and I'm about to upload a new version of the component...

J.Ja

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.