This document was generated from CDN thread
Created by: Asher Schweigart on 07-08-2012 02:43:19 PM
I'm creating a DB element to loop through rows returned from a db element, and I'd like to do it without a counter. I figured I'd use an element data field, and reference it's current value before incrementing it, but I can't figure out how to get the current value. I thought I should do:
public String doDecision(String name, DecisionElementData decisionData) throws ElementException
{
...
int savedCount = Integer.parseInt(decisionData.getElementData("savedCount"));
savedCount++;
decisionElementData.setElementData("savedCount", savedCount);
...
}
However, validating the code shows that getElementData is expecting two string arguments.
Am I using the wrong function to get the element data?
Subject: RE: Get Element Data in custom java element
Replied by: Binny Mathew on 08-08-2012 02:43:05 AM
Hi Asher,
getElementData always needs 2 input arguments first being the Element name for which you are trying the get the value and second the attribute (eg:- "value")
But i am not sure what are you trying to achieve here. What is "savedCount"? Is it some session variable you are setting somewhere and using it here?
Below is an example of the usage of getElementData
public String doDecision(String name, DecisionElementData decisionData) throws ElementException
{
...
String strMenuName= data.getElementHistory().get(data.getElementHistory().size()-2); // gets you the previous name of the element
String strCallerOption = data.getElementData(strMenuName,"value"); // Gets you the bvalue returned by the element (strMenuName)
...
}
Note: There are other possible values to the second parameter of getElementData i am not sure of that probabaly you can check that out in the doc.
Also setElementData can be done only locally to that Element i.e you can not set value for a form element in a decision class.
Hope i have answered to the context meant by you.
Binny
Subject: RE: New Message from Binny Mathew in Customer Voice Portal (CVP) - CVP - Al
Replied by: Asher Schweigart on 08-08-2012 10:22:12 AM
Thanks, that makes sense. I was suspecting it was something like that.
In your example, are you getting the name of the parent element of the current element, or is it two levels up? What would be the best way of getting the name of the current element?
Basically what I am trying to do is combine a counter element with an element that retrieves a row from a multiple row database query. That way I can create a loop on the element without having to determine or specify the number of rows, and I can just make it exit the loop on a ‘no data’ path when there are now more rows.
Subject: Re: New Message from Asher Schweigart in Customer Voice Portal (CVP) - CVP
Replied by: Janine Graves on 08-08-2012 11:12:27 AM
To find the name of the current element, it's passed as the first parameter into the doDecision or doAction. Janine
Subject: Re: New Message from Asher Schweigart in Customer Voice Portal (CVP) - CVP
Replied by: Janine Graves on 08-08-2012 05:40:27 PM
Hi Asher,
I think you'll need to do something like this:
public String doDecision(String name, DecisionElementData decisionData)
throws ElementException
{
int savedCount;
//check whether the element data savedCount exists for this current
element.
//if not, this is the first time executing in the call flow
//so, create the element data savedCount with value 1
if( (savedCount=decisionData.getElementData(name, "savedCount")) ==
null){
//this is the first time executing, create and set the variable to 1
//note that element data is always set as a string value
decisionData.setElementData("savedCount","1");
} else {
//if the element data 'savedCount' exists, then just increment it
and then store it back into element data
savedCount++;
//note that element data is always set as a string value
//that's why I'm adding an empty string. Probably better ways to
convert an into to string!
decisionElementData.setElementData("savedCount", savedCount + "" );
}
. . .
}
Subject: RE: Get Element Data in custom java element
Replied by: Binny Mathew on 09-08-2012 01:53:34 AM
Yes in the example mentioned i am getting the parent element of the current element. If you need to get the name of the current element you can do the below
...
String currentElement= decisionElementData.getElementHistory().get(decisionElementData.getElementHistory().size()-1);
...
The above will always give you the name of the Element the flow is in.
Binny
Subject: Re: New Message from Binny Mathew in Customer Voice Portal (CVP) - CVP - Al
Replied by: Janine Graves on 09-08-2012 08:48:27 AM
And the name of the current element is also passed as the first
parameter to the doDecision or doAction method.