Java STACK.pop()
-
Hannah Kleinen2 years ago #30025
Hey everyone,
I would like to remove the last element of a stack, so I used stack.pop():
var la_partialStackSequence = this.getGlobals().getVar(“ga_PartialStackSequence”);
la_partialStackSequence.pop();this.getGlobals().setVar(“ga_PartialStackSequence”, la_partialStackSequence);
Unfortunately it doesn´t work. Did I use this function correctly? Or is there another solution to remove the last element?
Armin WinklerHas successfully completed the online course IntroductionHas successfully completed the online course Intermediate (200)Has successfully completed the online course Advanced (300)Has successfully completed the online course Basics (100)2 years ago #30034::Hi Hannah,
your script seems to work fine for me and pop should be the correct function to use if you want to remove the last element of an array / stack. Can you provide us with more detail about your use case so we get a better understanding what could be the problem for you? Have you tried to inspect the state of the global variable before and after executing the pop function? Does the variable contain all the elements it should before the function is invoked? Or is it not properly assigned to begin with?
For testing purposes you can create a new variable in your application and select the data type “ITIZ_User_Col” for it. After doing so, you can add some values to your array by clicking on default value and then hitting the + button on the collection several times. This adds some user structs to your array of users. Of course it’s also helpful to provide some meaningful values for the properties first name and last name, just to be able to differentiate between the different elements later on. When you’re done setting the variable and inserting some dummy users, you can add a script block to your process logic and connect it to an event subscription block where you select the onAfterRendering event of the screen that is initially loaded on app start. You can paste your script 1:1 to that script block but please also add a debugger statement in front of the first line, so your application will stop on that line on a breakpoint when you load the application with developer console opened.
Hope this helps!
Regards,
Armin
Vitali KurdasovHas successfully completed the online course Intermediate (200)Has successfully completed the online course Basics (100)Has successfully completed the online course Advanced (310)Has successfully completed the Intermediate Certification2 years ago #30035::Hi Hannah,
the pop function works, as we also use it in some applications.
Have you checked if the value of your global variable is actually an array?
Where do you use that code sample(application script block, serverside businessobject, clientside buisness object)?
Here’s also a quick reference to the documentation: Array.prototype.pop()
You must be logged in to reply to this topic.