0th element?
I have a few other tokens that come after that reference the created merged list, such as this:
${mergedOpptyAndAVMList.get(0).ITEMFROMAVMLIST__c}
Well you can’t have those without checking if the list is empty. Trying to referencing the first/[0]th element of an empty list is always a fatal error. Just like referencing the second/[1]th element of a list with only one element.
Got it, I've updated the first token that calls this to as follows:
#if( ! $display.alt($mergedOpptyAndAVMList,"").isEmpty() )
#foreach(ITEMFROMAVM in mergedOpptyAndAVMList)
#set($AVMCurrentValue=${mergedOpptyAndAVMList.get(0).ITEMFROMAVM})
I get this error:
Large number of errors there. Typos and logic as a whole.
This will at least compile (assuming it’s only the top of your token and you’re #ending that #if and #foreach later on):
#if( !$display.alt($mergedOpptyAndAVMList,[]).isEmpty() )
#foreach( $avm in $mergedOpptyAndAVMList )
## $avm is set to the current item in $mergedOpptyAndAVMList
But I don’t get what you’re trying to do with the list. As it iterates, $avm is set to each object in the list in turn. You should never, ever be referencing object [0].
This might be where there is some coding teaching here, what is object[0]? Sorry, I'm trying based on what languages and logic structures I know, but I'm sure it's not the prettiest, apologies for that and thank you again for helping.
As far as what I'm doing, maybe it will help if I user story it. Now that we have the mergedOpptyAndAVMList, there are three different values based on what the list was merged on that I want to display in the email. I had created the three tokens to pull each, and I was doing each as mergedOpptyAndAVMList.Item1, mergedOpptyAndAVMList.Item2, and mergedOpptyAndAVMList.Item3, where the .item is what the item was called from the AVM list.
Does that make more sense?
I think there is an understanding gap around how the foreach loop works:
#if( ! $display.alt($mergedOpptyAndAVMList,"").isEmpty() )
#foreach(ITEMFROMAVM in mergedOpptyAndAVMList)
#set($AVMCurrentValue=${mergedOpptyAndAVMList.get(0).ITEMFROMAVM})
By object[0], @SanfordWhiteman is referring to the generic notion of the zero indexed item of a list (the zero indexed item is the FIRST item). If you try to access the [0] item in an empty list, it errors as there is no first item (as it is empty). Substitute 'object' for the name of the list you are using (i.e. mergedOpptyAndAVMList) to make it specific to your use case.
I have to profess, I don't understand your use case as you've explained it. Sorry.
Cheers
Jo
So I asked our engineering team for some assistance, and we did some debugging. We're able to go into the Opportunity Loop, but when we loop through the AVM, nothing happens. So in the code below, we get pineapple, but not oranges. Is there something basic I'm missing? I've checked ALL of the values within the AVM custom object in the script token.
#set( $HackermanValue1= "Apple")
#if( !$OpportunityList.isEmpty() && !$AVM_Values__cList.isEmpty() )
#foreach( $oppty in $OpportunityList )
#set( $HackermanValue1 = "pineapple")
#foreach( $avm in $AVM_Values__cList )
#set( $HackermanValue1 = "oranges")
#end
#end
#end
${HackermanValue1}
Am I missing something obvious? I can see values within AVM dataset, so I know they aren't empty.
Am I missing something obvious? I can see values within AM dataset, so I know they aren't empty.
What do you see when you simply output
${AVM_Values__cList}
?
That needs to be part of your testing — dumping the raw data.