Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Populating a field that combines 2 different fields

Posted on by 53
Good Day,
 
I am trying to combine 2 fields from the QA Header table and combine them in a single table in the Lot No Information table. I have managed to combine these fields but the problem I have is that the /Sample Result/ value always default to the last value I have entered in the QA Header Table. Below is my QA Header table:

The result that I am expecting to see in the Lot No Information table is: A-Pass, B-Reject, C-Resample. Currently I get the below result:


Can you please advise where I am going wrong? I have a feeling that it is in the QA Header repeat loop but cannot find a way to get this working correctly. Please see my code below which is on the QA Header Table:
 
 trigger OnAfterModify()
    begin
        UpdateLotRes(0);
    end;
 
    var
        TempLotDetail: Record /Lot Detail/ temporary;
        TempQAHeader: Record /QA Header/ temporary;
 
    procedure UpdateLotRes(_option: Option Insert,Delete,Rename)
    var
        _lotNoInfo: Record /Lot No. Information/;
    begin
        if _lotNoInfo.Get(/Source No./, /Source No. 2/, /Source No. 3/) then begin
            _lotNoInfo./APTOCB_SampleResults/ := BuildVLStringRes(_option);
            _lotNoInfo.Modify;
        end;
    end;
 
    procedure BuildVLStringRes(_option: Option Insert,Delete,Rename): Text[1024]
    var
        _lotNoInfo: Record /Lot No. Information/;
        _codeString: Code[1024];
        _QAHeader: Record /QA Header/;
    begin
        TempLotDetail.Reset;
        TempLotDetail.DeleteAll;
        TempQAHeader.Reset();
        TempQAHeader.DeleteAll();
 
        if _lotNoInfo.Get(/Source No./, /Source No. 2/, /Source No. 3/) then begin
            if _lotNoInfo.APTOCB_PreSampleItem = true then begin
                _QAHeader.SetRange(/Source No./, /Source No./);
                _QAHeader.SetRange(/Source No. 2/, /Source No. 2/);
                _QAHeader.SetRange(/Source No. 3/, /Source No. 3/);
                If _QAHeader.FindSet() then begin
                    repeat
                        if _option = _option::Insert then begin
                            InsertTempRes(_QAHeader.APTOCB_VendorLotSerialNo, 0);
                            InsertTempSample(_QAHeader.APTOCB_TempSample, 0);
                        end;
                        if _option = _option::Delete then begin
                            _lotNoInfo./APTOCB_SampleResults/ := '';
                        end;
                        if _option = _option::Rename then begin
                            if xRec.APTOCB_VendorLotSerialNo = _QAHeader.APTOCB_VendorLotSerialNo then begin
                                InsertTempRes(APTOCB_VendorLotSerialNo, 0);
                                InsertTempSample(TempQAHeader.SampleResults, 0);
                            end else begin
                                InsertTempRes(_QAHeader.APTOCB_VendorLotSerialNo, 0);
                                InsertTempSample(TempQAHeader.SampleResults, 0);
                            end;
                        end;
 
                        _codeString += ',' + TempLotDetail./Lot No./ + '-' + GetOptionText(TempQAHeader.APTOCB_TempSample);
 
                    until _QAHeader.Next = 0;
                end;
 
                _codeString := DelChr(_codeString, '<', '-');
                _codeString := DelChr(_codeString, '<', ',');
                exit(CopyStr(_codeString, 1, 250));
 
            end else begin
                TempLotDetail.Reset();
                if TempLotDetail.FindSet then begin
                    repeat
                        if StrLen(_codeString + ',' + TempLotDetail./Lot No./ + '-' + GetOptionText(TempQAHeader.APTOCB_TempSample)) < 1024 then begin
                            _codeString := '0';
                        end
                    until TempLotDetail.Next = 0;
 
                    _codeString := DelChr(_codeString, '<', '-');
                    _codeString := DelChr(_codeString, '<', ',');
                    exit(CopyStr(_codeString, 1, 250));
                end;
            end;
        end;
    end;
 
    procedure InsertTempRes(_lotNo: Code[20]; _sort: Integer)
    begin
        TempLotDetail.SetRange(/Lot No./, _lotNo);
        if not TempLotDetail.FindFirst then begin
            TempLotDetail.Init;
            TempLotDetail./Lot No./ := _lotNo;
            TempLotDetail.Insert;
        end;
    end;
 
    local procedure InsertTempSample(_sample: Option; _sort: Integer)
    begin
        TempQAHeader.SetRange(/Source Type/, _sample);
        if not TempQAHeader.FindFirst then begin
            TempQAHeader.Init;
            TempQAHeader.APTOCB_TempSample := _sample;
            TempQAHeader.Insert;
        end;
    end;
 
    local procedure GetOptionText(Sample: Option): Text
    var
        OptionText: Text;
    begin
        case SampleResults of
            SampleResults::Pass:
                OptionText := 'Pass';
            SampleResults::/Pass - Brand/:
                OptionText := 'Pass - Brand';
            SampleResults::/Pass - Custom/:
                OptionText := 'Pass - Custom';
            SampleResults::/Pass - Private Label/:
                OptionText := 'Pass - Private Label';
            SampleResults::Reject:
                OptionText := 'Reject';
            SampleResults::Resample:
                OptionText := 'Resample';
            else
                OptionText := '';
        end;
        exit(OptionText);
    end;
Thanks for the assistance
Categories:
  • Divan Profile Picture
    Divan 53 on at
    Populating a field that combines 2 different fields
    Thanks YUN ZHU, I have created the combine table in the QA Header and passed that value through my Procedure BuildVLStringRes, This works 100%
  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 71,565 Super User 2024 Season 2 on at
    Populating a field that combines 2 different fields
    Hi, sorry I didn't look at your code in detail, there is a simple way. You can combine it on the QA Header first, such as adding a Combine Field and combining it in the OnValidate Trigger of the Vendor Lot and  the Sample Result. Then just pass this value over.
     
     
    Hope this can give you some hints.
     
    Thanks.
    ZHU

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,900 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,275 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans