Separate list items with "," is not working properly

I have a List Records that has a checkbox and a expression. 


The checkbox variable is a calculated attribute "ListRecords1.List.Current.IsSelected", the expression is the user status label ListRecords1.List.Current.UserStatus.Label. I want to store in a text variable CheckedStatusIds all of the user status selected by the user.


 So I have an action with a foreach, the Record List of the foreach is "ListRecords1.List", then there is a condition "ListRecords1.List.Current.IsSelected = True" and then an assign "SelectedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")". 


The issue is in the assign because is necessary to separate each id with a comma, but with this code is not working. 

 "CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")"


Hi OsCaR_

What do you mean by "is not working"?

What is the result you are getting?

Cheers

By the way, it will not provide what you want, anyway.

Use something like this:

CheckedStatusIds + If(CheckedStatusIds <> "", ",", "") + ListRecords1.List.Current.UserStatus.Id

The problem is that you don't know when last selected row will be achieved, so you can't use this as a definition for the place of the comma or not.

Hi,

Can you share a snapshot of Expression or Post a Correct s expression, as of the one you posted is quoted under a String.

 "CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")"

If it is under string then do remove & make it as:

 CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")


Hope it helps,

Assif

assif_tiger wrote:

Hi,

Can you share a snapshot of Expression or Post a Correct s expression, as of the one you posted is quoted under a String.

 "CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")"

If it is under string then do remove & make it as:

 CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")


Hope it helps,

Assif


Thanks, but like that: CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "") dont works properly maybe because for example if the user selected only one status (one checkbox) the id of the status is stored in the CheckedaStatus variable as "3," and so it appears an error in the query, probably because of th comma "3,".

OsCaR_ wrote:

assif_tiger wrote:

Hi,

Can you share a snapshot of Expression or Post a Correct s expression, as of the one you posted is quoted under a String.

 "CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")"

If it is under string then do remove & make it as:

 CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")


Hope it helps,

Assif


Thanks, but like that: CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "") dont works properly maybe because for example if the user selected only one status (one checkbox) the id of the status is stored in the CheckedaStatus variable as "3," and so it appears an error in the query, probably because of th comma "3,".

what is your expected result, can you share the Screenshot so that folks here can guide you with a Correct Expression.

It is very difficult to suggest expression without proper knowledge :)


Please, try my solution :)

Cheers.

assif_tiger wrote:

OsCaR_ wrote:

assif_tiger wrote:

Hi,

Can you share a snapshot of Expression or Post a Correct s expression, as of the one you posted is quoted under a String.

 "CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")"

If it is under string then do remove & make it as:

 CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")


Hope it helps,

Assif


Thanks, but like that: CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "") dont works properly maybe because for example if the user selected only one status (one checkbox) the id of the status is stored in the CheckedaStatus variable as "3," and so it appears an error in the query, probably because of th comma "3,".

what is your expected result, can you share the Screenshot so that folks here can guide you with a Correct Expression.

It is very difficult to suggest expression without proper knowledge :)



The expected result is for example, if the user checks, for example the checkboxes associated with the status "active, deleted, inactive", the CheckedStatusIds should store 2,3,1. So 2 is the id of active, 3 of deleted and 1 of inactive. And the last item of the list dont have ",".

Ok, another way:

CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + ","

And in the end, remove the last character. 

SubStr(CheckedStatusIds, 0, Length(CheckedStatusIds) - 1)


OsCaR_ wrote:

assif_tiger wrote:

OsCaR_ wrote:

assif_tiger wrote:

Hi,

Can you share a snapshot of Expression or Post a Correct s expression, as of the one you posted is quoted under a String.

 "CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")"

If it is under string then do remove & make it as:

 CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")


Hope it helps,

Assif


Thanks, but like that: CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "") dont works properly maybe because for example if the user selected only one status (one checkbox) the id of the status is stored in the CheckedaStatus variable as "3," and so it appears an error in the query, probably because of th comma "3,".

what is your expected result, can you share the Screenshot so that folks here can guide you with a Correct Expression.

It is very difficult to suggest expression without proper knowledge :)



The expected result is for example, if the user checks, for example the checkboxes associated with the status "active, deleted, inactive", the CheckedStatusIds should store 2,3,1. So 2 is the id of active, 3 of deleted and 1 of inactive. And the last item of the list dont have ",".


Great,

Do refer Eduardo Jauch answer.

or 

What I got from your requirement you can refer below:

CheckedStatusIds+If(ListRecords1.List.CurrentRowNumber < ListRecords1.List.Length -1, ",", "")


Output : 2,3,4


Hope it helps,

Assif

Hi, 

By 'in the end' I mean after the looping you create the string, remove the last character using the expression with SubStr built-in function and assign the result back to your string. 

Eduardo Jauch wrote:

Hi, 

By 'in the end' I mean after the looping you create the string, remove the last character using the expression with SubStr built-in function and assign the result back to your string. 


Thanks, but its not working correctly. 

For exmaple if I check at first the status "Active" (that has Id 3) and click in the submit button: 

The CheckedStatusIds appears like "3," in the foreach and also after the foreach with the assign "CheckedStatusIds = Substr(CheckedStatusIds, 0, Length(CheckedStatusIds) - 1) ". 

Then if I check the status "Active" and "Deleted" (Deleted status has id 4) and click in the submit button again: 

The CheckedStatusIds appears like "33," instead of "3,3" and then in the foreach, because the Deleted status was also checked, in one of the foreach iterations appears CheckedStatusIds like "33,4," instead of "3,4" and then after the foreach the assign "CheckedStatusIds = Substr(CheckedStatusIds, 0, Length(CheckedStatusIds) - 1)" appears also like "33,4,".

To explain better the context, I have a ListRecords with checkboxes and a expression and below a graph to show the number of users in each status, for the checked statuses. 

The checkbox variable is "ListRecords1.List.Current.IsSelected". 

The expression is "ListRecords1.List.Current.UserStatus.Label". 

When the user click in the button "Show" there is a Show action (method Ajax submit) that: 

- has a foreach "ListRecords1.List" 

- in the foreach there is an if "ListRecords1.List.Current.IsSelected = True" 

- if the if condition is true there is an assign CheckedStatusIds = CheckedStatusIds + ListRecords1.List.Current.UserStatus.Id + ","

 - after the foreach there is the assign "CheckedStatusIds = Substr(CheckedStatusIds, 0, Length(CheckedStatusIds) - 1)"

 - after this assign there is a refresh to the preparation query and an ajax refresh to update the graph

 - in the preparation there is the query to show the graph and then an aggregate to get the user statuses, that runs at first if the IsLoadingScreen() is True, and if the IsLoadingScreen() is false there is a GetUserStatuses.List = ListRecords1.List to maitain the previous checked checkboxes checked

Solution

Please, see attached file.

Solution

Thanks, it seems that also works like this " CheckedStatusIds+ If(CheckedStatusIds = "", "", ",") + ListRecords1.List.Current.UserStatus.Id", howeve, Im not understanding properly, because like this it seems that is not taking in account the last item on the list and what is necessary is to have a "," between every two items, except for the last item.

Hi OsCaR_

It works because it checks if already exists an item in the list when adding a new one. 

Like this.

                         The IF decides
New Item    List Now    Should Add Comma?  List AFTER add New Item
   1         EMPTY             NO                     1
   2           1               YES                   1,2
   4          1,2              YES                  1,2,4 

And so on.

Cheers