OnPrintLabel_OnAfterPopulateDataset

Use this event to

Modify label data before transfer to the Cloud Print Service

  • Make sure you are only handling the desired template
  • Use GetValue/SetValue to modify the dataset


See also:

Customize Labels

Standard Label Template Designs


Template

    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB Print", 'OnPrintLabel_OnAfterPopulateDataset''', true, true)]
    local procedure OnPrintLabel_OnAfterPopulateDataset(_TemplateName: Text[50]; _SourceRecRef: RecordRefvar _Dataset: Record "MOB Common Element")
    begin
    end;


 Click here for parameters...
  • _TemplateName
    • Name of the template to handle
  • _RequestValues
    • Mobile the context the print is called from. E.g. header fields like Location, Item or ReferenceID.
  • _SourceRecRef
    • A RecordRef to the context the print is called from.
    • I.e. Sales Order Line, Warehouse Receipt Line, Purchase Order Return Line, Warehouse Activity(Pick, Put-away) etc.
  • _Dataset
    • The Print Dataset . Use the dataset and determine which steps you want to collect


Example 1: Modify labels on Item Label

    // Read the Item No. from Dataset and change it 

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB Print", 'OnPrintLabel_OnAfterPopulateDataset', '', true, true)]
    local procedure onPrintLabel_OnAfterPopulateDataset(_TemplateName: Text[50]; var _RequestValues: Record "MOB NS Request Element"; _SourceRecRef: RecordRef; var _Dataset: Record "MOB Common Element")
    var

        // Making sure we only handle our own Label-Template
        if _TemplateName <> 'My custom Label-Template' then
            exit;

        // Read the Item No. from Dataset and change it 
        // Item No. could have been collected or transferred from "context"/source table, where the print action was selected by the user 
        if _Dataset.GetValue('ItemNumber''ItemA' then
            _Dataset.SetValue('ItemNumber''ItemB');
    end;

Example 2: Included Default Bin as Extrainfo

Standard Label Template Designs has extrainfo fields you can use to include new information.


    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB Print", 'OnPrintLabel_OnAfterPopulateDataset', '', true, true)]
    local procedure onPrintLabel_OnAfterPopulateDataset(_TemplateName: Text[50]; var _RequestValues: Record "MOB NS Request Element"; _SourceRecRef: RecordRef; var _Dataset: Record "MOB Common Element")
    var
        Item: Record Item;
        BinContent: Record "Bin Content";
    begin
        // Item labels are always called with an Item. Else exit
       if not Item.Get(_Dataset.GetValue('ItemNumber')) then
            exit;

        BinContent.SetRange("Location Code", _RequestValues.Get_Location());
        BinContent.SetRange("Item No.", Item."No.");
        BinContent.SetRange(Default, true);

        if BinContent.FindFirst() then begin
            _Dataset.SetValue('ExtraInfo01', BinContent."Bin Code");
            _Dataset.SetValue('ExtraInfo01_Label', BinContent.FieldCaption(Default));
        end;
    end;

Example 3: Set ExtraInfo fields and their labels

Standard Label Template Designs has extrainfo fields you can use to include new information.


    // Read Source record
    // Set ExtraInfo fields, their labels in dataset

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB Print", 'OnPrintLabel_OnAfterPopulateDataset', '', true, true)]
    local procedure onPrintLabel_OnAfterPopulateDataset(_TemplateName: Text[50]; var _RequestValues: Record "MOB NS Request Element"; _SourceRecRef: RecordRef; var _Dataset: Record "MOB Common Element")
    var
        Item: Record Item;
        Vendor: Record Vendor;
    begin


        // Making sure we only handle our own Label-Template
        if _TemplateName <> 'Item Label 4x6' then
            exit;

        // If source is "Item" = Get record from RecordRef
        if _SourceRecRef.Number = database::Item then
            _SourceRecRef.SetTable(Item);

        // Set extrainfo fields and their labels in the Dataset
        _Dataset.SetValue('ExtraInfo01_Label''Desc.');
        _Dataset.SetValue('ExtraInfo01', Item.Description);

        _Dataset.SetValue('ExtraInfo02_Label''GTIN');
        _Dataset.SetValue('ExtraInfo02', Item.GTIN);

        _Dataset.SetValue('ExtraInfo03_Label''Purchasing Unit');
        _Dataset.SetValue('ExtraInfo03', Item."Purch. Unit of Measure");

        _Dataset.SetValue('ExtraInfo04_Label''Vendor');
        if Vendor.Get(item."Vendor No."then
            _Dataset.SetValue('ExtraInfo04', Vendor.Name);

        // Additional custom values can also be used on the label
        _Dataset.SetValue('CustomValueA''A');
        _Dataset.SetValue('CustomValueB''B');

    end;



More examples

  

Version History

VersionChanges
MOB5.16Introduced