CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
Showing results for 
Search instead for 
Did you mean: 
0 Kudos

The complete source code used in this series could be found from my github repository.

In previous blog when a Wechat user subscribes the subscription Wechat account, a new individual customer is automatically created in C4C system.

So technically Wechat is the source(sender) of dataflow and our C4C system is the dataflow target ( receiver ), and the nodejs server acts as a middleware.

In this blog, let's try the other way around: suppose any one has made changes on this automatically created account in C4C system, the corresponding Wechat user will receive a notification in his/her Wechat app. Such notification is sent by C4C and Wechat app is the receiver.

Implementation detail

1. Since in the third blog of this series, I use the standard field "LastName" of Customer BO to store the Wechat ID of the user who has performed the subscription,

and later in C4C, any user could change this field.

As a result in this blog, I create a new extension field in common node of Customer BO to store the Wechat ID.

import AP.Common.GDT;
import AP.FO.BusinessPartner.Global;

[Extension] businessobject AP.FO.BusinessPartner.Global:Customer {
// root node of Customer is not extendable
node Common {
[Label("Wechat ID")] element WechatID:LANGUAGEINDEPENDENT_EXTENDED_Text;

And create a new BeforeSave.absl to copy the value of FamilyName into extension field WechatID.

import ABSL;
var common = this.Common.GetFirst();
if( common.WechatID.IsInitial()) {
common.WechatID = common.Person.Name.FamilyName;

2. Create a new OData service to expose this WechatID, mark field ObjectID, ParentObjectID and WechatID.

Test this OData Service via url:

https://<your tenant>/sap/c4c/odata/cust/v1/zindividualcustomer/CustomerCommonCollection?$filter=ParentObjectID%20eq%20%2700163E20C9511EE7B8975BD4AB3F60C0%27

Make sure it can return the correct value of three fields as expected:

3. Once the account is changed in C4C, a notification should be sent from C4C to our nodejs server. This automatic notification mechanism could be achieved via C4C OData event notification. See another of my blog Leverage C4C Odata notification to monitor C4C Opportunity change in CRM system for detail.
The setting below means whenever a change on Customer BO occurs in C4C, a change notification will be sent to the endpoint automatically:

So far all development / configuration in C4C side is done.

4. In nodejs server implementation, create a new field in config object:

  • field name: indivudualCustomerNewurl

  • field value: https://<your tenant>/sap/c4c/odata/cust/v1/zindividualcustomer/CustomerCommonCollection?$filter=

Since the endpoint I configure in C4C system is:

And when a given account is changed in C4C, a HTTP post with the following kind of payload will be sent to this endpoint:

{"businessObject":"CUSTOMER","businessObjectId":"00163E20C9511EE7B8975BD4AB3F60C0","event":"","odataServiceEndpoint":"https://<your tenant>/sap/byd/odata/v1/zindividualcustomer/CustomerCommonCollection('00163E20C9511EE7B8975BD4AB3F60C0')"}

So in nodejs server, I have to react to this Post request.

Main logic is implemented in module notifyWechatUser, which uses the guid of changed Customer BO instance as an input parameter.

Inside the implementation of notifyWechatUser, which consists of two steps:

function notifyWechatUser(uuid,res){
console.log("begin to read uuid: " + uuid);
sendMessage(wechatID, "Dear user, A kind reminder: your C4C account is changed in the system.");

1. call _getAccount to get the WechatID stored on Common node of Customer BO via OData call.

2. Once WechatID is available, call sendMessage to send a hard coded sentence to the corresponding Wechat user.

Implementation of _getAccount

function _getAccount(uuid) {
var AccountBOguid = uuid;
var detailODataUrl = config.indivudualCustomerNewurl;
var parentID = 'ParentObjectID eq \'' + AccountBOguid + '\'';
detailODataUrl = detailODataUrl + encodeURI(parentID);
var getOptions = {
url: detailODataUrl,
method: "GET",
headers: {
"content-type": "application/json",
'Authorization': 'Basic ' + new Buffer(config.credential).toString('base64')
return new Promise(function(resolve,reject){
var requestC = request.defaults({jar: true});
console.log("request with url: " + detailODataUrl);
var wechatID = body.d.results[0].WechatID;
console.log("wechat id: " + wechatID);
}); // end of requestC

Implementation of sendMessage

var config = require("../../config.js");
var request = require("request");

function printObject(oData){
for( var a in oData){
console.log("key: " + a);
console.log("value: " + oData[a]);
if( typeof oData[a] === "object"){

function sendWCMeaasge(toUser,sMessage){
console.log("begin to send message to user: " + toUser + " with message: " + sMessage);
var options = {
url:"" +
method: "POST",
headers: {
"content-type": "application/json"},
console.log("error? " + error);
console.log("response: " + response);
console.log("data: " + data);
console.log("Status message: " + response.statusMessage);
console.log("Data: " + data.errmsg);

module.exports = sendWCMeaasge;

Final achievement

As soon as I subscribe the test Wechat account by scanning QRCode, a new account 1000443 is created in C4C system.

When this account is changed in the system:

The corresponding Wechat user successfully received the notification sent by C4C in the Wechat app:

The complete source code used in this series could be found from my github repository.