Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

check for existing job numbers and increment them if they exist

Posted on by 28
When it enters the loop it should check if a job number already exists or not if exists it should increment like 001 to 002

for example Sell-to Customer No = 1000
job number will be1000-001
if 1000-001 exist the it should increment to 1000-002

code:
trigger OnAfterValidate()
            var
                GetNo: Text;
            begin
                GetNo := '';
                Rec.get(rec./No./);
                if Rec.FindSet() then
                    repeat
                        GetNo := Rec./Sell-to Customer No./ + '-' + IncStr('001');
                        Rec./No./ := GetNo;
                        Rec.Rename(GetNo);
                    until Rec.Next() = 0;
            end;
Categories:
  • Suggested answer
    Ben Baxter Profile Picture
    Ben Baxter 4,559 Super User 2024 Season 2 on at
    check for existing job numbers and increment them if they exist
    I would argue the case you do not need your Customer Number included in your Project/Job No.
     
    On the Project you select the Customer of that Project.  From the Customer you can look up their Projects.  From the Project list you can Search (or Filter) for your Customer No., and it will show all Projects for that Customer.
     
    There is really no need to include the Customer No. in the Project No.  This could be an example of developing something from the old system that didn't have the features/capabilities Business Central does for linking Customers and Projects.
     
    Best Regards,
    Ben Baxter
    Accent Software Inc
  • Suggested answer
    JM Profile Picture
    JM 56 on at
    check for existing job numbers and increment them if they exist
    Hi there!
     
    As Yhun Zhu has commented, if you are trying to increment No. Series for documents you need to use the standard feature.
     
    However for the sake of resolution, basing on your code, here is my suggestion. The following code checks if a job number already exists for a customer and increments the suffix accordingly:
     
     
     
    A more 'elegant' solution would be in any case to generate those auto incremental job numbers utilizing the existing Business Central No. Series functionality (No. Series Management Codeunit), which is realiable and well-integrated.
     
    Hope it helps! 
     
    BR,
    JM
     
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 69,639 Super User 2024 Season 2 on at
    check for existing job numbers and increment them if they exist
    It sounds like you can do it with the standard No. Series feature. For example, you can define a No. Series for each customer. When creating a job, the system can automatically pick up the number.
     
    More details:
    Dynamics 365 Business Central: No. Series Relationships (Multiple Number Series)
    Dynamics 365 Business Central: New “No. Series” module
     
     
    Hope this helps.
    Thanks.
    ZHU
     
  • Suggested answer
    Saurav.Dhyani Profile Picture
    Saurav.Dhyani 17,959 Super User 2024 Season 2 on at
    check for existing job numbers and increment them if they exist
    Hi,
     
    I am not sure what you are trying to do but
     
    To put it simply once you get new number generated - Just verify using If not .GET() then assign value otherwise keep repeating.
     
    Regards,
    Saurav Dhyani

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans