Home > Forum > Rules, JS, SQL > Remove Item from collection

Remove Item from collection
0

Hi everyone!
Am I blind or there is no function oposite to COLLECTION, that would remove an element from collection? How do you manage to overcome the lack of this function?

I came up with an idea of making a JS form rule that takes a collection and removes a value given in one of the parameters. It works. But there are limitations that make the solution inelegant. First of all the form rule can not return a value (in opposition to business rules, but those however can not contain Javascript), which requires to use an outside technical variable to hold the output of the rule. Again... it works, but could be more elegant.

In reply to: Christian Amler

Hi Michał,

couldn't you put a replace around it and replace the string you dont want in the collection?

Replace(Replace('1#value1;4#something;18#another choice','4#something',''),';;',',')

On the other hand "SELECT Replace(Replace('1#value1;44#something;18#another choice','4#something',''),';;',',')" will not work in certain cases. If you will try to remove "'4#something" i this case you will end up with: "1#value1;4;18#another choice" - not acceptable.

In reply to: Michał Ludwiczak

On the other hand "SELECT Replace(Replace('1#value1;44#something;18#another choice','4#something',''),';;',',')" will not work in certain cases. If you will try to remove "'4#something" i this case you will end up with: "1#value1;4;18#another choice" - not acceptable.

True ;) You need to know what might be in the collection to remove values. How do you know what you want to remove?

Also there was a typo in my post, it would replace ';;' with ','.

SELECT Replace(Replace('1#value1;44#something;18#another choice','4#something',''),';;',';')

MVP
In reply to: Christian Amler

True ;) You need to know what might be in the collection to remove values. How do you know what you want to remove?

Also there was a typo in my post, it would replace ';;' with ','.

SELECT Replace(Replace('1#value1;44#something;18#another choice','4#something',''),';;',';')

Hi everyone,

I'm joining the conversation, also I'm not sure whether there's really something left to do here and the biggest question is, how to determine which element is unwanted. Nevertheless I will leave another approach:

In my case changing the "Without id" value will execute the form rule, which in turn will execute a business rule. The values of "SourceField" and "WithoutId" are passed to the business rule. The rule, will split the string into a table, "remove" the row with the provided id an merge the result back to a single string.
SQL statement
select STUFF(
(
select ';'+dbo.ClearWFElemId(item)+'#'+ dbo.ClearWFElem(item)
from dbo.SplitToTable('{BRP:13}',';')
where dbo.ClearWFElemId(item) <> '{BRP:12}'
FOR XML PATH('')
),1,1,'') as cleanedCollection

Instead of

select ';'+dbo.ClearWFElemId(item)+'#'+ dbo.ClearWFElem(item)
This should also work but I haven't tested it

select ';'+item

This happens when you don't clean up after you have a working solution. On the other hand, maybe someone doesn't know either function. So I will leave them there. :)

Best regards,
Daniel