cancel
Showing results for 
Search instead for 
Did you mean: 

Get value in UDF dynamically

Former Member
0 Kudos

Hi Gurus,

I have an importstructure which can be enhanced dynamiccaly hence not all fields are defined and available in the mapping. Now there is a field which is not defined in the importstructure that contains a value I want to read.

I'm trying to create an UDF which reads a value from a structure dynamically. The path of this field is given as an inputparameter (KVK).


public String Bepaal(Container container) throws StreamTransformationException{

Document doc = null;

String value = null;

try {

    String inParam = container.getInputParameters().getString("KVK");

    //Bouw document op o.b.v. intpustream

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setNamespaceAware(false);

    DocumentBuilder builder = factory.newDocumentBuilder();

    doc = builder.parse(<How do I get the inputstream??>);

           

    //Bouw xpath expressie t.b.v. het ophalen van de base64 gecodeerde waarde

    XPathFactory xFactory = XPathFactory.newInstance();

    XPath xpathExpr = xFactory.newXPath();

    XPathExpression expr = xpathExpr.compile(inParam);

    Object result = expr.evaluate(doc, XPathConstants.NODESET);

           

    //Bepaal gevonden node(s) en bepaal de waarde van de eerstgevonden waarde in de lijst

    NodeList nlList = (NodeList) result;

    value = nlList.item(0).getNodeValue();

}

catch (Exception e) {

    container.getTrace().addWarning(e.toString());

    return "";

}

return value;

}

return value

;

The problem is, how do I get the inputstream? I only have a container element.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member184720
Active Contributor
0 Kudos

If you are on PI > 7.1, then you can make use of the return as xml feature.

Write the below UDF to get the value of the dynamic attribute value.

Just map the root node to target field and check the "Return as XML".

UDF :

Former Member
0 Kudos

Thanks, this is somewhat helpfull but the field I need is a but more difficult to find, it is not unique.

I need the value in field IdValue where idOwner = "KvK".

Is this possible?

<AdditionalData>

    <StaffingAdditionalData>

      <CustomerReportingRequirements>

        <PurchaseOrderNumber>4357435</PurchaseOrderNumber>

        <CustomerReferenceNumber>43545453443</CustomerReferenceNumber>

        <PurchaseOrderLineItem>00001</PurchaseOrderLineItem>

      </CustomerReportingRequirements>

      <ReferenceInformation>

        <OrderId idOwner="StaffingCustomer">

          <IdValue>546576653</IdValue>

        </OrderId>

        <StaffingSupplierId idOwner="StaffingCustomer">

          <IdValue>346554</IdValue>

        </StaffingSupplierId>

        <StaffingSupplierId idOwner="KvK">

          <IdValue>547365737635</IdValue>

        </StaffingSupplierId>

        <StaffingCustomerId idOwner="StaffingCustomer">

          <IdValue>FC70</IdValue>

        </StaffingCustomerId>

        <StaffingCustomerId idOwner="OIN">

          <IdValue>57645654646</IdValue>

        </StaffingCustomerId>

      </ReferenceInformation>

    </StaffingAdditionalData>

  </AdditionalData>

former_member184720
Active Contributor
0 Kudos

May be you can repeat the same UDF?

for the first one

int i=s.indexOf("<StaffingSupplierId idOwner=\"kvk\">"),j=s.indexOf("</StaffingSupplierId>");

s=s.substring(i+"<StaffingSupplierId idOwner=\"kvk\">".length(),j);

for the second one :

int i=s.indexOf("<IdValue>"),j=s.indexOf("</IdValue>");

s=s.substring(i+"<IdValue>".length(),j);

former_member184720
Active Contributor
0 Kudos

To make it generic, you can make use of the below UDF:

S -> return as xml

a-> starting tag i.e. <StaffingSupplierId idOwner="kvk">,<IdValue>

b->ending tag i.e. </StaffingSupplierId>, </IdValue>

try

{

int i=s.indexOf(a),j=s.indexOf(b);

if (i>0)

{

s=s.substring(i+a.length(),j);

}

else{

s="";

}

}

catch(Exception e)

{

e.printStackTrace();

}

return s;


Mapping:

Input field -> UDF(StaffingSupplierId )-> UDF(IdValue)->target field.