
Business Partner Integration to SAP Sales Cloud via MDI
Name: ObjectIdentifierMapping
NameSpace: http://sap.com/xi/CommunicationServicesManagement/Global
Node: Root
Event: "BeforeSave"
Mass Enabled: checked
/*
SAP Business ByDesign scripting language implementation for:
Business Object: ObjectIdentifierMapping
Node: Root
Event: BeforeSave
*/
import ABSL;
import AP.Common.GDT;
import DocumentServices.Global;
import CommunicationServicesManagement.Global;
// pre-filter on ID type
var relevantIDMappings = this.Where(
n => n.RemoteIdentifierDefiningSchemeCode == "20" // ERP Materials
|| n.RemoteIdentifierDefiningSchemeCode == "27"); // ERP Plants
if (relevantIDMappings.Count() == 0) {
return; // fast exit: no relevant ID type
}
// determine business systems involved
var sourceBusinessSystemID : CommunicationSystemParticipatingBusinessSystemID;
var targetBusinessSystemID : CommunicationSystemParticipatingBusinessSystemID;
if (Context.IsProductionTenant()) {
sourceBusinessSystemID.content = "PW9CLNT100"; // adjust these business system IDs
targetBusinessSystemID.content = "PW9CLNT300"; // to fit your specific environment
} else {
sourceBusinessSystemID.content = "QW9CLNT100"; //
targetBusinessSystemID.content = "QW9CLNT300"; //
}
var sourceBusinessSystem = CommunicationSystem.ParticipatingBusinessSystem.Retrieve(sourceBusinessSystemID);
var targetBusinessSystem = CommunicationSystem.ParticipatingBusinessSystem.Retrieve(targetBusinessSystemID);
if (!sourceBusinessSystem.IsSet() && !targetBusinessSystem.IsSet()) {
// either source or target BusinessSystem ID is incorrect
return;
}
// filter on source business system
relevantIDMappings = relevantIDMappings.Where(n => n.RemoteBusinessSystemUUID.content == sourceBusinessSystem.UUID.content);
if (relevantIDMappings.Count() == 0) {
return; // another fast exit: no ID mapping for the relevant business systems
}
// copy once per ID scheme type
foreach (var IDtype in relevantIDMappings.DistinctBy(n => n.RemoteIdentifierDefiningSchemeCode)) {
// restrict mapings relevant based on current ID scheme type
var sourceIDMappings = relevantIDMappings.Where(n => n.RemoteIdentifierDefiningSchemeCode == IDtype.RemoteIdentifierDefiningSchemeCode);
// query for existing target mappings
var targetIDMappingQuery = ObjectIdentifierMapping.QueryByElements;
var targetIDMappingQueryParams = targetIDMappingQuery.CreateSelectionParams();
targetIDMappingQueryParams.Add(targetIDMappingQuery.RemoteBusinessSystemUUID.content, "I", "EQ", targetBusinessSystem.UUID.content);
targetIDMappingQueryParams.Add(targetIDMappingQuery.RemoteIdentifierDefiningSchemeCode, "I", "EQ", IDtype.RemoteIdentifierDefiningSchemeCode);
foreach (var sourceIDMapping in sourceIDMappings) {
targetIDMappingQueryParams.Add(targetIDMappingQuery.LocalObjectNodeReference.UUID.content, "I", "EQ", sourceIDMapping.LocalObjectNodeReference.UUID.content);
}
var targetIDMappings = targetIDMappingQuery.Execute(targetIDMappingQueryParams);
// process mappings
foreach (var sourceIDmapping in sourceIDMappings) {
// check target mapping existence
var targetIDMapping = targetIDMappings.Where(n => n.LocalObjectNodeReference.UUID.content == sourceIDmapping.LocalObjectNodeReference.UUID.content);
var count = targetIDMapping.Count();
if (count == 0) {
// create id mapping
var newIDMapping = ObjectIdentifierMapping.Create();
newIDMapping.LocalObjectNodeReference.ObjectID.content = sourceIDmapping.LocalObjectNodeReference.ObjectID.content;
newIDMapping.LocalObjectNodeReference.ObjectNodeTypeCode.content= sourceIDmapping.LocalObjectNodeReference.ObjectNodeTypeCode.content;
newIDMapping.LocalObjectNodeReference.ObjectTypeCode.content = sourceIDmapping.LocalObjectNodeReference.ObjectTypeCode.content;
newIDMapping.LocalObjectNodeReference.UUID.content = sourceIDmapping.LocalObjectNodeReference.UUID.content;
newIDMapping.RemoteBusinessSystemUUID.content = targetBusinessSystem.UUID.content;
newIDMapping.RemoteIdentifierDefiningSchemeCode = sourceIDmapping.RemoteIdentifierDefiningSchemeCode;
newIDMapping.RemoteObjectID.content = sourceIDmapping.RemoteObjectID.content;
newIDMapping.OriginTypeCode = sourceIDmapping.OriginTypeCode;
} else if (count == 1) {
// update id mapping
targetIDMapping.GetFirst().RemoteObjectID.content = sourceIDmapping.RemoteObjectID.content; }
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |