Connect Sales and Service with ICS

Tweet about this on TwitterShare on Facebook4Share on LinkedIn17Share on Google+0

Oracle ICS is a solution that facilitate the integration between SaaS x SaaS and SaaS x On-Premise solutions.
It has a lot of connectors to help you to create your integrations throught configuration.
Two examples are Oracle Sales and Oracle Service (formerly Oracle RightNow) connectors.
For some Business Objects of Oracle Sales and Oracle Service you can use a feature called Event Subscription, and it means that if you create, update or delete a registry of this objects, the integration inside ICS will start automatically.
Today, this feature is only enabled for Contact and Account in Oracle Sales.

And only enabled for Contact, Organization and Incident in Oracle Service.

In this post, I will show how to integrate objects without Event Subscription feature.
In ICS, go to Connectors and create a connector for Oracle Sales.

Create other connector for Oracle Service.

Go to Integration and create an integration (Map Data) called “OSC_SVC_Opportunity_Created” that will be started by Oracle Sales.

In Sales connector, choose Opportunity as business Object.

In Service connector, choose Opportunity as business Object and Create as operation.

Map the fields you want.

Specify a tracking field.

Activate the integration.

Create other integration (Map Data) called “SVC_OSC_Opportunity_Created” that will be started by Oracle Service.

In Sales connector, choose Opportunity as business Object.
In Service connector, choose Opportunity as business Object and CreateOpportunity as operation.

Map the fields you want.

Specify a tracking field.

Activate the integration.

The interactions are active.

In Oracle Sales, go to Navigator > More… > Application Composer.
Go to Web Services and create a SOAP Web Service Connection.

Go to Opportunity object > Server Scripts and create an Object Trigger using the following code.

if ( nvl(OptyLastUpdatedBy,"") != "LISA.JONES" ) {
  println("Name=" + Name)
  def Opportunity = [[Name: Name]]
  adf.webServices.OSC_SVC_Opportunity_Created.process(Opportunity)
}

In Oracle Service, go to Process Designer and create an Object Event Handler called “SVC_OSC_Opportunity_Created” using the following code.

<?php
/**
 * CPMObjectEventHandler: SVC_OSC_Opportunity_Created
 * Package: OracleServiceCloud
 * Objects: Opportunity // [Note] : Name of the object.
 * Actions: Create // [Note] : Name of the operations on the object above for which the PHP code will be executed
 * Version: 1.2
 */
use \RightNow\Connect\v1_2 as RNCPHP;
use \RightNow\CPM\v1 as RNCPM; 

class SVC_OSC_Opportunity_Created implements RNCPM\ObjectEventHandler
{
    public static function apply($runMode, $action, $obj, $cycle)
    {
        if($cycle !== 0) return ;
		
		$url = "https://integration-gse00010027.integration.us2.oraclecloud.com/integration/flowsvc/rightnow/SVC_OSC_OPPORTUN_CREATED/v01/";
			
		$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/pcbpel/cloud/connector/rightnow/types" xmlns:v1="urn:base.ws.rightnow.com/v1_3">
				   <soapenv:Header>
					  <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
						 <wsu:Timestamp wsu:Id="TS-9812ABB85C59DDAEAE1486908131141128">
							<wsu:Created>'.gmdate("Y-m-d\TH:i:s\Z").'</wsu:Created>
						 </wsu:Timestamp>
						 <wsse:UsernameToken wsu:Id="UsernameToken-9812ABB85C59DDAEAE1486850556658126">
							<wsse:Username>username</wsse:Username>
							<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
							<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">PmmBGfNqlklaajriOku6Zg==</wsse:Nonce>
							<wsu:Created>2017-02-11T22:02:36.658Z</wsu:Created>
						 </wsse:UsernameToken>
					  </wsse:Security>
				   </soapenv:Header>
				   <soapenv:Body>
					  <typ:process>
						 <typ:RNObjects xsi:type="ns4:Opportunity" xmlns:ns4="urn:objects.ws.rightnow.com/v1_3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
							<ns4:Name>'.$obj->Name.'</ns4:Name>
						 </typ:RNObjects>
					  </typ:process>
				   </soapenv:Body>
				</soapenv:Envelope>';
		
                
			$header[0]= "Content-Type: text/xml;charset=UTF-8";
            $header[1]= 'SOAPAction: "process"';
             
            load_curl();
            $curl = curl_init();
            curl_setopt_array($curl,array(
              CURLOPT_URL => $url,            
              CURLOPT_HEADER => 0,
              CURLOPT_HTTPHEADER => $header,  
              CURLOPT_FOLLOWLOCATION => 1, 
              CURLOPT_RETURNTRANSFER => 1,
              CURLOPT_CONNECTTIMEOUT => 20,
              CURLOPT_SSL_VERIFYPEER => 0,
              CURLOPT_SSL_VERIFYHOST => 0,
  
            ));
            curl_setopt($curl,CURLOPT_POST,TRUE);
            curl_setopt($curl,CURLOPT_POSTFIELDS, $xml);
            $content = curl_exec($curl);
    }
}
/**
 * CPM test harness
 */
// [Note] : These are unit test functions, needed by the RN PHP framework.
class SVC_OSC_Opportunity_Created_TestHarness
        implements RNCPM\ObjectEventHandler_TestHarness
{
    /**
     * Set up test cases.
     */
    public static function setup()
    {
        
    }
    /**
     * Return the object that we want to test with. You could also return
     * an array of objects to test more than one variation of an object.
     * @param int $action
     * @param class $object_type
     * @return object | array
     */
    public static function fetchObject($action, $object_type)
    {
        return array();
    }
    /**
     * Validate test cases
     * @param int $action
     * @param object $contact
     * @return bool
     */
    public static function validate($action, $contact)
    {
        echo "Test Passed!!";
        return true;
    }
    /**
     * Destroy every object created by this test. Not necessary since in
     * test mode and nothing is committed, but good practice if only to
     * document the side effects of this test.
     */
    public static function cleanup()
    {
        
    }
}
?>

Go to Opportunity object and choose “SVC_OSC_Opportunity_Created” in create option.

Done!
To test, create an opportunity in Sales.

And confirm in Service.

Create other opportunity in Service.

And confirm in Sales.

Tweet about this on TwitterShare on Facebook4Share on LinkedIn17Share on Google+0

Author: Waslley Souza

Consultor Oracle com foco em tecnologias Oracle Fusion Middleware e SOA. Certificado Oracle WebCenter Portal, Oracle ADF e Java.

Leave a Reply

Your email address will not be published. Required fields are marked *