Remove last element from $lb property
How can I remove elements from $lb property? Specifically last element?
$list does not work with $lb properties.
$listupdate can't remove elements
The only solution I found is a temp variable and $list, but isn't there something better?
Class User.Test Extends %RegisteredObject
{
Property List As %List [ InitialExpression = {$lb(1,2,3)} ];
/// do ##class(User.Test).TestList()
ClassMethod TestList()
{
set obj = ..%New()
do obj.ClearLast()
set list = obj.List
zw list
}
Method ClearLast()
{
//set $list(..List, *, *) = "" // <OBJECT DISPATCH>zTestList+2^User.Test.1 *Property 'List' in class 'User.Test' must be MultiDimensional
//set ..List = $LISTUPDATE(..List, $ll(..List), "") // Works, but returns $lb(1,2,"")
// works
set list = ..List
set class = $lg(list, *)
set $list(list, *, *) = ""
set ..List = list
}
Seems like
works.
Nice!
Wow.Very Nice..
This is a very nice solution !
I prefer this solution as it is in full accordance with the documentation and
with no need also for beginners to fiddle into internals .
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_flist
<snip>
</snip>
Hi.
Recently, well yesterday, I needed to do exactly the same , and on a class property as well! I found an answer more by accident than design:
When I saw the other answer, I worried that this might not work when the result is only one item, but it does, as confirmed by the documentation for the $LIST function. If you supply all three parameters - list, position, end - then it always returns another list. I was pleasantly surprised!
Mike
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue