Codeunit 5397 CDS Transformation Rule Mgt.

Base Application, Microsoft.Integration.Dataverse

src/Layers/W1/BaseApp/Integration/Dataverse/CDSTransformationRuleMgt.Codeunit.al57 lines, Copyright (c) Microsoft Corporation. MIT

// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace Microsoft.Integration.Dataverse;using Microsoft.Integration.SyncEngine;using System.IO;codeunit 5397 "CDS Transformation Rule Mgt."{    var        TransformationRuleInUseErr: Label '%1 cannot be deleted because it is in use.', Comment = '%1 - the name of the transformation rule';    [EventSubscriber(ObjectType::Table, Database::"Transformation Rule", 'OnBeforeDeleteEvent', '', false, false)]    procedure OnDeleteTransformationRule(var Rec: Record "Transformation Rule"; RunTrigger: Boolean)    begin        if Rec.IsTemporary() then            exit;        if IsTransformationRuleInUse(Rec) then            Error(TransformationRuleInUseErr, Rec.Code);    end;    local procedure IsTransformationRuleInUse(Rec: Record "Transformation Rule"): Boolean    var        IntegrationFieldMapping: Record "Integration Field Mapping";    begin        IntegrationFieldMapping.ReadIsolation := IsolationLevel::ReadCommitted;        IntegrationFieldMapping.SetRange("Transformation Rule", Rec.Code);        exit(not IntegrationFieldMapping.IsEmpty());    end;    procedure ApplyTransformations(SourceRecordRef: RecordRef; var DestinationRecordRef: RecordRef; IntegrationTableMapping: Record "Integration Table Mapping")    var        IntegrationFieldMapping: Record "Integration Field Mapping";        TransformationRule: Record "Transformation Rule";        CRMSynchHelper: Codeunit "CRM Synch. Helper";    begin            IntegrationFieldMapping.SetRange("Integration Table Mapping Name", IntegrationTableMapping.Name);        IntegrationFieldMapping.SetFilter("Transformation Rule", '<>%1', ' ');        if IntegrationFieldMapping.FindSet() then            repeat                if TransformationRule.Get(IntegrationFieldMapping."Transformation Rule") then                    case IntegrationFieldMapping."Transformation Direction" of                        IntegrationFieldMapping."Transformation Direction"::FromIntegrationTable:                            if IntegrationTableMapping."Integration Table ID" = SourceRecordRef.Number() then                                CRMSynchHelper.TransformValue(SourceRecordRef, DestinationRecordRef, TransformationRule, IntegrationFieldMapping."Integration Table Field No.", IntegrationFieldMapping."Field No.");                        IntegrationFieldMapping."Transformation Direction"::ToIntegrationTable:                            if IntegrationTableMapping."Table ID" = SourceRecordRef.Number() then                                CRMSynchHelper.TransformValue(SourceRecordRef, DestinationRecordRef, TransformationRule, IntegrationFieldMapping."Field No.", IntegrationFieldMapping."Integration Table Field No.");                    end;            until IntegrationFieldMapping.Next() = 0;    end;}