Post Closed
31
Views
8
Comments
Text Separator
Application Type
Traditional Web
Service Studio Version
11.11.15 (Build 48647)

Hi All,

i want to add separator "," after i looped.

as an example:

CAR_TABLE

ID|COLOR|ID_CUSTOMER

1  |BLACK |10

2  |WHITE |12

3  |RED      |20

I do a loop on the CAR_TABLE, where the ID column I will put into SALES_TABLE in the ID_CAR column with the separator ",".

and the results in the SALES_TABLE will be like this

SALES_TABLE

ID|NAME   |ID_CAR|ADD_TIME

1  |Batman|1,2,3     |10.35


Thanks

Kane.

mvp_badge
MVP

Hi @Kane Loony ,

When you looped in action for Car_Table  take a one Variable like ID_Car

once you looped on Car_Table assign

ID_Car as if(ID_Car="",CarTable.list.current.entityName.ID,ID_Car+","+CarTable.list.current.entityName.ID)

And use thi ID_Car as output or assign in Sales table column name.


Hope this will help you.

Regards
Rahul

Hi @Rahul Sahu ,

Thanks I have tried this method and it works,


But FYI, actually my goal is to store many ids with the separator to display data on another screen where the ID collection with the separator I will display the data based on the ID and I will split the ID


Regards,

Kane

mvp_badge
MVP

"But FYI, actually my goal is to store many ids with the separator to display data on another screen where the ID collection with the separator I will display the data based on the ID and I will split the ID" - yes, it's clear that's your goal, but like I wrote before it is a bad idea! This is not what you should do, and there's no need to do it like this as there are better altenatives (already explained)!

I'm going to close this topic now, as I think we've discussed everything there is to discuss. tl;dr don't do this.

Hi Kane,

it might be easier to create an Entity like 'Sales_Cars' that contains the SalesId and CarId. and that add every car that 'Batman' wants into the Sales_Car entity. 

It will make it easier when you want to select the Cars, since you can just join entities using an aggregate.

Do you have a specific reason that you want to use a comma seperated list? 

regards Hans

mvp_badge
MVP

Agreed, 

This is solution is nice instead of saving ids as separator after that when you want view it also take extra effort .

Hi @Hans Dollen ,


My purpose of saving the id with the separator has been explained above in my comment, and I'm looking for a suitable idea


Regards,

Kane

Hi Kane,

after storing a value into Sales_Cars, you can do a String_Join over all cars belonging to that sale and store the result redundantly into Sales.CarIds.

see https://success.outsystems.com/Documentation/11/Reference/OutSystems_APIs/Text_API#String_Join about how to use String_Join.

Regards, Hans

mvp_badge
MVP

Completely agree with Hans. In case you have an n:n relationship in a database, you need an associative entity (a.k.a. link table). Not sure why you think you need to put Ids as Text with a seperator, but that's a very, very bad idea.