web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Populating a field that combines 2 different fields

(0) ShareShare
ReportReport
Posted on by 107
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
I have the same question (0)
  • Verified answer
    YUN ZHU Profile Picture
    99,974 Super User 2026 Season 1 on at
    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
  • Divan Profile Picture
    107 on at
    Thanks YUN ZHU, I have created the combine table in the QA Header and passed that value through my Procedure BuildVLStringRes, This works 100%

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,024 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,145 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 705 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans