cancel
Showing results for 
Search instead for 
Did you mean: 

Fieldglass and CPI - Groovy concatenate ID and description in incoming description tag

gabrielmendes
Advisor
Advisor
0 Kudos

Hello, we are integrating Fieldglass and we have a limitation in Line Items extrinsic custom fields, we need to send the MaterialID to the ERP, Fieldglass can send the values in the XML but the mapping tool designed for the CPI iflow doesnt have an option to map this field(so the value is lost) so we are trying to map this through Groovy script.

<urn:ExternalReqForApprovalImportRequest xmlns:urn="urn:Ariba:Buyer:vrealm_1" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" partition="" variant="">
	<urn:ExternalReqForApprovalInput_Item>
		<urn:item>
			<urn:Name>Servicios de limpieza</urn:Name>
			<urn:Operation>NEW</urn:Operation>
			<urn:ExternalReqId>OCENTQ00000099</urn:ExternalReqId>
			<urn:HeaderComments/>
			<urn:ExternalReqLineItems>
				<urn:item>
					<urn:ExternalLineNumber>2</urn:ExternalLineNumber>
					<urn:ItemDescription>TEST DESCRIPTION</urn:ItemDescription>
					<urn:Quantity>1.00</urn:Quantity>
					<urn:LineExtrinsics>
						<Extrinsics>
							<Extrinsic name="InternalID">7000083</Extrinsic>
							<Extrinsic name="MaterialGroup">MAC_00</Extrinsic>
						</Extrinsics>
					</urn:LineExtrinsics>
				</urn:item>
			</urn:ExternalReqLineItems>
		</urn:item>
	</urn:ExternalReqForApprovalInput_Item>
</urn:ExternalReqForApprovalImportRequest>

The idea is to store the LineNumber and the InternalID, so the Message Mapping executes and then after, we do the additional assignment for this value.

Our problem is that in the Groovy script i cannot map the Extrinsic field required, i tried several tests but looks like we dont have the right logic to map correctly the extrinsic value (we can actually map correctly the LineNumber)

We did a simple iflow with the payload as Body from Content mapping and tried this groovy:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.io.*;
def Message processData(Message message) {      
            def body = message.getBody(java.io.Reader);
            HashMap<Integer, String> hmap = new HashMap<Integer, String>();
            def Root = new XmlSlurper().parse(body);
    Root.ExternalReqForApprovalInput_Item.item.ExternalReqLineItems.item.each{
        try{          
        hmap.put(it.ExternalLineNumber.text().toString(), it.LineExtrinsics.Extrinsics.Extrinsic.@'InternalID'.text().toString());
        }
        catch(Exception ex){
            //put relevant exception handling here
        }
    }
            message.setProperty("hashmapdata", hmap);
            return message;
}

What we are trying for now is just store a Property to check that our code is running correctly, the mapping for ItemDescription is correct, but the one for the deeper level Extrinsic with attribute name InternalID doesn't store the value.

Can somebody confirm that we can work with it directly to get the deeper level? or we need to do a for or looping to get to that level so we can create the record in the Hashtable?

Thank you

Accepted Solutions (0)

Answers (0)