ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

Extensibility Request: [W1][Codeunit][30316][Shpfy Metafield API] - OnBeforeCollectMetafieldsInBC for Empty Value Handling

Open ReneGubler opened this issue 3 months ago • 1 comments

Why do you need this change?

Currently, CollectMetafieldsInBC filters out empty values (Metafield.SetFilter(Value, '<>%1', '')), causing a critical issue:

Problem: When a metafield value is cleared/emptied in BC, it's NOT collected for export. The old value remains in Shopify, creating data inconsistency.

Benefits:

  • Proper synchronization of metafield deletions
  • Data consistency between BC and Shopify
  • Support for business scenarios requiring metafield clearing (expired promotions, etc.)
  • Custom logic for handling empty values based on business rules

Alternative Solution: Simply remove the Metafield.SetFilter(Value, '<>%1', '') filter from the standard code, as the Shopify API can handle empty values and delete metafields when empty values are sent. However, an event provides more flexibility for partners who may want different behavior.

Describe the request

Add an event before the filter is applied in CollectMetafieldsInBC to allow extensions to handle empty metafields.

Event Signature

[IntegrationEvent(false,false)]
local procedure OnBeforeCollectMetafieldsInBC(
    ParentTableId: Integer;
    OwnerId: BigInteger;
    var TempMetafieldSet: Record "Shpfy Metafield" temporary;
    MetafieldIds: Dictionary of [BigInteger, DateTime];
    var Handled: Boolean
)
begin
end;

Modified Procedure Logic

local procedure CollectMetafieldsInBC(ParentTableId: Integer; OwnerId: BigInteger; 
    var TempMetafieldSet: Record "Shpfy Metafield" temporary; 
    MetafieldIds: Dictionary of [BigInteger, DateTime])
var
    Metafield: Record "Shpfy Metafield";
    UpdatedAt: DateTime;
    Handled: Boolean;
begin
    // NEW: Event for custom collection logic
    OnBeforeCollectMetafieldsInBC(ParentTableId, OwnerId, TempMetafieldSet, MetafieldIds, Handled);
    
    if Handled then
        exit;
    
    // Default logic (unchanged)
    Metafield.SetRange("Parent Table No.", ParentTableId);
    Metafield.SetRange("Owner Id", OwnerId);
    Metafield.SetFilter(Type, '<>%1&<>%2', Metafield.Type::string, Metafield.Type::integer);
    Metafield.SetFilter(Value, '<>%1', ''); // Filter out empty values
    
    // ... rest of existing logic ...
end;

ReneGubler avatar Aug 06 '26 13:08 ReneGubler

Hi @ReneGubler,

Thank you for your extensibility request.

The code you'd like to change is part of the BCApps repository. To have this change made, it needs to go through a contribution. Please refer to the contribution guide for instructions on how to proceed: https://github.com/microsoft/BCApps/blob/main/CONTRIBUTING.md

[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

[!TIP] Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

github-actions[bot] avatar Aug 06 '26 13:08 github-actions[bot]