AnsweredAssumed Answered

How to get the two field values from XML profile through the Groovy Script by using data process Shape

Question asked by divya_tirumalasetty755278 on Aug 6, 2018
Latest reply on Aug 6, 2018 by Lee Sobotkin

Hi Team,

 

I am getting a XML file from the message shape from there I need to get only few field names i.e., Preferred_Last_Name ,Preferred_First_Name,Last_Name and First_Name I am trying to retrieve the field with the Groovy script using data process shape I am using the below script but I am not sure what is mistake I am doing in here I am not getting the results.

 

Can any one help me. 

 

// This script manipulates an XML Document's structure.

import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.xpath.XPath;
import org.jdom.output.XMLOutputter;

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

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


SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(input);

x = XPath.newInstance("//DATA_DS.G_3.G_1");


String preferredFirstName = x.selectSingleNode(PREFERRED_FIRST_NAME);
String preferredLastName = x.selectSingleNode(PREFERRED_LAST_NAME);
String legalFirstName = x.selectSingleNode(FIRST_NAME);
String legalLastName = x.selectSingleNode(LAST_NAME);


if ( preferredFirstName == "" )
{firstName = legalFirstName}
else
{firstName = preferredFirstName}

if ( preferredLastName == "" )
{lastName = legalLastName}
else
{lastName = preferredLastName}

props.setProperty("document.dynamic.userdefined.firstName", firstName);
props.setProperty("document.dynamic.userdefined.lastName", lastName);
dataContext.storeStream(input, props);


}

 

Thanks!

Divya

Outcomes