Any coding or configuration examples provided in this document are only examples and are NOT intended for use in a productive system. The example is only done to better explain and visualize the topic.
The objective of the blog is to explain how we can integrate an external Credit Score Check solution to C4C Utilities. The assumption is that the External Credit Score solution exposes web services (REST/SOAP) which can be consumed to fetch the Credit Score for a customer.
Below is the detailed scope of this Blog -
- Create a solution in SAP Cloud Application Studio.
- Create a Custom BO which holds the information for external credit score.
- Create an Action to call the external API.
- Create a Custom EC.
- Embed the Custom EC to Customer TI.
1. Create a solution in SAP Cloud Application Studio
Provide the required information for creation of solution.
2. Create a custom BO to store External Credit Score
Create a new Business Object to store data related to external credit score.
Enhance the BO with below changes-
- Add field to store the credit score check.
- Add Customer UUID to create a link to the Customer BO.
- Add association to Customer BO.
- Add custom action to call external API.
import AP.Common.GDT as apCommonGDT;
import AP.FO.BusinessPartner.Global;
businessobject UtilitiesCustomerCreditScore {
[Label ("External Credit Score")] element ext_credit_score:DecimalValue;
[AlternativeKey] element CustomerUUID:UUID;
association ToCustomer[0,1] to Customer;
action FetchCreditScore;
}
3. Implement the FetchCreditScore Action
This action would call the external API (REST/SOAP) and fill the extension field for External Credit Score with the corresponding value.
To call external Web Services, please refer to the SDK documentation -
https://help.sap.com/sdk. Detail documentation for Web services can be found under Developer Desktop-> Web Services -> External Web Service Integration in the SDK documentation.
I have illustrated a sample implementation for the FetchCreditScore action taking a Rest based service as an example.
import ABSL;
import AP.FO.BusinessPartner.Global;
// Communication details
var ScenarioName = "GetCreditScore";
var ServiceName = "GetCreditScoreByCustomerID";
var HttpMethod = "GET";
var HttpResource = ""; // not required for this example
var ContentType = ""; // not required for this example
var Body = ""; // not required for this example
var HeaderParameter : collectionof NameAndValue; // not required for this example
// Set URL Parameter
var URLParameter : collectionof NameAndValue;
var URLParameterEntry : NameAndValue;
var instance;
foreach(instance in this){
if(!instance.CustomerUUID.content.IsInitial()){
// Retrieving Customer Root Information
var customerObj = Customer.Retrieve(instance.CustomerUUID);
if(customerObj.IsSet()){
// Get all the Customer information required for external Rest based service.
var customerId = customerObj.InternalID;
var customerName = customerObj.CurrentCommon.BusinessPartnerFormattedName;
//Fill URL Parameters required for the external Rest based service.
URLParameterEntry.Name = "customerID";
URLParameterEntry.Value = customerId;
// Execute webservice call
var ws_result = WebServiceUtilities.ExecuteRESTService(ScenarioName, ServiceName,
HttpMethod, HttpResource, URLParameter, HeaderParameter, ContentType, Body);
//Parse result of Web service and retrieve credit score; you may have to adapt the logic to the Web service used
var startPosition;
var length;
// Get start position and length after parsing the result. Finally fill the value for Ext_Credit_Score.
instance.ext_credit_score = ws_result.Content.Substring(startPosition, length);
}
}
}
4. Create a Custom Embedded Component
Click on Add Item and create a new Embedded Component.
4.1 Open the EC for Edit by selecting the "Open in UI Designer" option
4.2 Add fields and Action in the Designer. Change the Section Group Title
4.3 Bind the Custom BO in the Data Model
Add the fields Ext_Credit_Score and CustomerUUID to your data model.
4.4 Add an Inport to pass data into EC -
Inport is required to pass Customer UUID from Customer TI to EC. Also set the RequestFireOnInitialization property to true. This is required to fire the inport on initialization of the parent component. Also create an Event Handler EV_Read which configured for OnFire Event property of the Inport.
4.5 Configure the EV_Read Event Handler
Add BO Operation Read to read the Custom BO Instance for the incoming Customer UUID.
Add a Condition on Root/CustomerUUID field. If the CustomerUUID is not set in the data model, means an instance of the custom BO doesn't not exist for the particular CustomerUUID.
Configure Operation on the condition. If CustomBO instance does not exist, then create an instance and set the CustomerUUID from the CustomerUUID filled through the inport.
4.6 Add Action to Call External API
The event handler should be added to the OnClick property of the action button - Sync Credit Score.
5. Embed Custom EC to Customer TI
Finally the Custom EC can be embedded to the Customer TI – /BYD_COD/ServiceOnDemand/PrivateAccount/COD_SEOD_IND_ACCOUNT_TI.TI.uicomponent
And do the Outport-Inport Binding.
With above enhancement, Customer TI would look like -
Note : In the above implementation, the external credit score will only be fetched on click of the button.