Skip to main content

Notifications

Business Central forum
Suggested answer

check for existing job numbers and increment them if they exist

Posted on by 22
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,169 Super User 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 52 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 62,529 Super User 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 12,769 User Group Leader 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

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,907 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,189 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans