Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
RaghuVamseedhar
Active Contributor

     This document is about, performing lookups on SuccessFactors, when data is exposed using SFAPI.

     Lookups are possible using SFSF receiver channel (Adapter - SFSF, Message protocol -SOAP). Please check prabhat.sharma2's blog Successfactors communication channel supports UDF based Lookups. Let’s say for an interface, we process all employees. If there are thousands of employees, we have to perform thousands of lookups. To avoid it, we will retrieve all values in one lookup and perform multiple search on response. Instead of SELECT externalCode, name_en_US FROM FO_company WHERE externalCode = '110', we will use SELECT externalCode, name_en_US FROM FO_company to retrieve entire XML.

    

     For each employee we will get 'externalCode', we have to send corresponding 'name_en_US' to output.

Solution :-

Create receiver SFSF channel.


Mapping :-

First input parameter to udf_LookupSF_SFAPI is a constant - <urn:query xmlns:urn='urn:sfobject.sfapi.successfactors.com'><urn:queryString>SELECT externalCode, name_en_US FROM FO_company</urn:queryString></urn:query>

Second input parameter is a constant - externalCode

Third input parameter is a constant - name_en_US

Fourth input parameter is element where externalCode values is present in input - company

UDF 1 :- udf_LookupSF_SFAPI : Execution Type: 'Single Value'


public String udf_LookupSF_SFAPI(String query, Container container) throws StreamTransformationException {
    //This UDF will execute 'query' on SuccessFactors cloud server and response XML is sent out as output string.
    try {
        //Connect to SuccessFactors using SFSF receiver channel.
        SystemAccessor accessor = LookupService.getSystemAccessor(LookupService.getChannel("SuccessFactors", "BC_EmployeeCentral", "CC_SFSF_SFAPI_RCVR_Lookup"));
        //Send query to SuccessFactors server.
        XmlPayload payloadRequest = LookupService.getXmlPayload(new ByteArrayInputStream(query.getBytes()));
        Payload payloadResponse = accessor.call(payloadRequest);
        //Get response XML from web-service.
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(payloadResponse.getContent()));
        StringBuilder response = new StringBuilder();
        String line = "";
        while (line != null) {
            response.append(line);
            line = bufferedReader.readLine();
        }
        //'response' will have XML response from SuccessFactors.
        //Now we can use DOM or SAX or Regurlar expressions to perform the lookup on this response string.
        return response.toString();
    } catch (Exception ex) {
        throw new StreamTransformationException(ex.getMessage());
    }
}

UDF 2 :- udf_SearchInResponse : Execution Type : 'All Values of Queue'


public void udf_SearchInResponse(String[] xml, String[] element1, String[] element2, String[] values, ResultList result, Container container) throws StreamTransformationException {
    //This UDF will search for element1 in 'xml' and return corresponding element2.
    try {
        org.w3c.dom.Document doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new org.xml.sax.InputSource(new ByteArrayInputStream(xml[0].getBytes("utf-8"))));
        javax.xml.xpath.XPath xPath = javax.xml.xpath.XPathFactory.newInstance().newXPath();
        org.w3c.dom.NodeList nlElement1 = (org.w3c.dom.NodeList) xPath.evaluate("//" + element1[0], doc.getDocumentElement(), javax.xml.xpath.XPathConstants.NODESET);
        org.w3c.dom.NodeList nlElement2 = (org.w3c.dom.NodeList) xPath.evaluate("//" + element2[0], doc.getDocumentElement(), javax.xml.xpath.XPathConstants.NODESET);
        //Lookup Map will contain key value pair of element1 and element2.
        Map<String, String> lookupMap = new HashMap<String, String>();
        for (int i = 0; i < nlElement1.getLength(); i++) {
            lookupMap.put(nlElement1.item(i).getTextContent(), nlElement2.item(i).getTextContent());
        }
        //If input = ContextChange, then output = ContextChange.
        lookupMap.put(ResultList.CC, ResultList.CC);
        //Write corresponding value of key to output ResultList.
        for (String key : values) {
            String value = lookupMap.get(key);
            if (value == null) {
                result.addValue(key); //If there is no lookup value, output = input.
            } else {
                result.addValue(value);
            }
        }
    } catch (Exception ex) {
        throw new StreamTransformationException(ex.toString());
    }
}

Display Queue in Message Mapping :-

Advantages of this approach :-

1. Session management is handled by receiver SFSF channel.

2. Easy to maintain proxy details in receiver SFSF channel.

3. UDF and receiver SFSF channel can be reused for more lookups.


Related blogs :-

How to Model Successfactors SOAP and ODATA Entities using Eclipse Juno Tool.

Testing Integration with SuccessFactors SFAPI


6 Comments
Labels in this area