AnsweredAssumed Answered

Groovy Script Error.

Question asked by pyasaraveni on Jun 12, 2018
Latest reply on Jun 12, 2018 by pyasaraveni

Dear All

 

i am getting a below error when running the groovy script. i am new to groovy. and error getting elementValue(bolded in code)

Error:

Test execution of Testing With Message shape. completed with errors. Embedded message: Error executing data process; Caused by: No such property: elementValue for class: Script25 (in groovy script); Caused by: No such property: elementValue for class: Script25

 

script:

import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.xpath.XPath;
import org.jdom.output.XMLOutputter;
import com.boomi.execution.ExecutionUtil;


// Loop through the Process Documents
for ( int i = 0; i < dataContext.getDataCount(); i++ ) {

InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);

propName = "ENVIRONMENT";

// Set the Search character value.
String StringToSearch = "_";
// Retrieve current Process Property value
propValue = ExecutionUtil.getDynamicProcessProperty(propName );

// Build XML Document
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(is);

// Here's how to grab values from the current data

// Create an XPath statement to search for the element or elements you care about:
XPath x;
x = XPath.newInstance("/Message/Recipient/ReplyToQ");

// Select a single node and grab the actual value
eleMyElement = x.selectSingleNode(doc);

if (eleMyElement != null) {
String elementValue = eleMyElement.getText();
}


// Here's how to change the value of an existing element

// First, find the element using XPath as illustrated above, then just the value:
if(elementValue.indexOf(StringToSearch) != -1)
{
elemyElement.setText(elementValue);
}
else
{
elemyElement.setText(Propvalue+"_"+elementValue)
}

// When you're finished manipulating the XML data, you'll need to output the Document's data to an InputStream to pass to the next step in your Process work flow.

XMLOutputter outputter = new XMLOutputter();
is = new ByteArrayInputStream(outputter.outputString(doc).getBytes("UTF-8"));

dataContext.storeStream(is, props);

}

Outcomes