Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

check for existing job numbers and increment them if they exist

(1) ShareShare
ReportReport
Posted on by 32
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;
  • Suggested answer
    Ben Baxter Profile Picture
    Ben Baxter 5,262 Super User 2025 Season 1 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 49 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 77,925 Super User 2025 Season 1 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 14,300 Super User 2025 Season 1 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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans