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

Job Queue

(4) ShareShare
ReportReport
Posted on by 49
I have One Candidate table in that there is a Application Status field with Option Datatype and Option are Received, Selected, Rejected when I changed option to selected then using Job Queue I want to run a Codeunit and In that Codeunit the Scenario is like those candidate I have changed the Application status according to that Candidate designation code the Interview Rounds are declared in the Interviewround table if 5 Interview Rounds of Designation then 5 Records are Inserted in the InterviewMaster Table.
 
 
e.g. If I have three records as shown in Image in Candidate Table
 
I have selected CAD0001 then 

as shown in image that Candidate have designation DESG0001 Now in the Designation Table Desg0001 have 5 Interview Rounds as shown in ImageSo Now I have Inserted 5 Records in the InterviewMaster table with different rounds like Aptitude,Technical,Sales pitch as per designation

I have registered the Codeunit in Job Queue Page
so for that I have write these code in Codeunit
 
codeunit 50101 "Job Queue"
{
    trigger OnRun()
    var
 
    begin
        InsertInterviewData
    end;
 
    local procedure InsertInterviewData()
    var
        candidaterec: Record Candidate_Master;
        interviewroundrec: Record InterviewRound;
        interviewmasterrec: Record Interview_Master;
        designationcode: Code[20];
    begin
        candidaterec.Reset();
        candidaterec.SetRange(application_status, candidaterec.application_status::Selected);
        if candidaterec.FindSet() then begin
            interviewroundrec.Reset();
            interviewroundrec.SetRange(designation_code, candidaterec.candidate_applied_designation);
            designationcode := candidaterec.candidate_applied_designation;
            interviewroundrec.Ascending(true);
            interviewroundrec.FindSet();
            repeat
                interviewmasterrec.Init();
                interviewmasterrec.Validate(candidate_code, candidaterec.candidate_code);
                interviewmasterrec.designation_name := getdesignationname(designationcode);
                interviewmasterrec.interview_date := 0D;
                interviewmasterrec.interview_time := 0T;
                interviewmasterrec.interview_location := '';
                interviewmasterrec.Status := interviewmasterrec.Status::Created;
                interviewmasterrec.Insert(true);
            until interviewroundrec.hierarchy = 0;
 
        end;
 
    end;


 
    local procedure getdesignationname(var designationcode: Code[20]): Text;
    var
        designation_name: Text;
        designationrec: Record Designation;
    begin
        if designationcode <> '' then begin
            if designationrec.Get(designationcode) then begin
                designation_name := designationrec.Designation_name;
            end
            else begin
                designation_name := '';
            end;
        end;
 
        exit(designation_name)
 
    end;
 
}

 
 
but These is not working Properly so what is the reason behind these and also This type of Functionality is Possible or not in D365BC if yes then Give me Solution and Also if you have any Reference
  • Suggested answer
    YUN ZHU Profile Picture
    81,794 Super User 2025 Season 1 on at
    Job Queue
    According to your needs, I think it would be better to use Page Background Tasks, because you are not running it regularly, but only after performing a certain operation.
    Hope the following can give you some hints.
     
    PS:
    Dynamics 365 Business Central: How to run Job Queue via AL (Debug Job Queue in Sandbox???)
     
    Thanks.
    ZHU
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    14,928 Super User 2025 Season 1 on at
    Job Queue
    Yes, definitely it's possible. Your code isn’t working because it processes only one candidate and doesn't loop through all matching candidates or their interview rounds correctly. You've also missed calling .Next() in your loops, and the loop condition is incorrect. This functionality can be achieved in D365BC using a Codeunit and Job Queue, but you need to fix the loops, properly fetch and insert interview rounds for each candidate, and optionally update their status after processing to prevent duplicate inserts.
     
    codeunit 50101 "Insert Interview Data"
    {
        trigger OnRun()
        begin
            InsertInterviewData();
        end;
        local procedure InsertInterviewData()
        var
            candidaterec: Record Candidate_Master;
            interviewroundrec: Record InterviewRound;
            interviewmasterrec: Record Interview_Master;
            designationrec: Record Designation;
        begin
            // Loop through all candidates with Selected status
            if candidaterec.FindSet() then
                repeat
                    if candidaterec.application_status = candidaterec.application_status::Selected then begin
                        // Fetch interview rounds for the candidate's designation
                        interviewroundrec.Reset();
                        interviewroundrec.SetRange(designation_code, candidaterec.candidate_applied_designation);
                        if interviewroundrec.FindSet() then
                            repeat
                                interviewmasterrec.Init();
                                interviewmasterrec.Validate(candidate_code, candidaterec.candidate_code);
                                interviewmasterrec.designation_name := GetDesignationName(candidaterec.candidate_applied_designation);
                                interviewmasterrec.interview_round_name := interviewroundrec.interview_round_name; // Assuming this field exists
                                interviewmasterrec.interview_date := 0D;
                                interviewmasterrec.interview_time := 0T;
                                interviewmasterrec.interview_location := '';
                                interviewmasterrec.Status := interviewmasterrec.Status::Created;
                                interviewmasterrec.Insert(true);
                            until interviewroundrec.Next() = 0;
                        // Optional: Change status to avoid inserting again next time
                        candidaterec.application_status := candidaterec.application_status::Processed; // Create a new status if needed
                        candidaterec.Modify();
                    end;
                until candidaterec.Next() = 0;
        end;
        local procedure GetDesignationName(designationcode: Code[20]): Text;
        var
            designationrec: Record Designation;
        begin
            if designationrec.Get(designationcode) then
                exit(designationrec.Designation_name)
            else
                exit('');
        end;
    }
     
  • Suggested answer
    Holly Huffman Profile Picture
    5,917 on at
    Job Queue
    Good morning, afternoon, or evening depending on your location!
     
    Yes, this type of functionality is possible in Dynamics 365 Business Central (D365BC), but there are a few potential issues you've got here:
     
    1. Issue with FindSet and Looping
    • In your InsertInterviewData procedure, you are using FindSet() for both candidaterec and interviewroundrec. However, the repeat...until loop for interviewroundrec is not properly structured to exit when all records are processed.
    • Solution: Use a proper condition to exit the loop. For example:
      repeat
          // Your logic here
      until interviewroundrec.Next() = 0;
    2. Hierarchy Field in InterviewRound
    • You are using interviewroundrec.hierarchy = 0 as the exit condition for the loop. Ensure that the hierarchy field is correctly populated and that the condition aligns with your data structure.
    • Solution: Verify the data in the InterviewRound table and adjust the condition if necessary.
    3. Validation and Initialization
    • The Validate method is used for the candidate_code field, but ensure that all required fields in the InterviewMaster table are properly initialized before inserting the record.
    • Solution: Add validations for all mandatory fields in the InterviewMaster table to avoid runtime errors.
    4. Job Queue Registration
    • Ensure that the Codeunit is properly registered in the Job Queue and that the Job Queue is active.
    • Solution: Go to the Job Queue Entries page in D365BC and verify that the Codeunit is set up correctly with the appropriate Object ID and parameters.
    5. Debugging and Logs
    • Use the debugger in D365BC to step through the code and identify where it is failing. Additionally, add logging to capture errors or unexpected behavior.
    • Solution: Insert log entries using the Log table or Message function to track the flow of execution.
    Example Adjusted Code
    Here’s an updated version of your InsertInterviewData procedure with some channges 

    local procedure InsertInterviewData()
    var
        candidaterec: Record Candidate_Master;
        interviewroundrec: Record InterviewRound;
        interviewmasterrec: Record Interview_Master;
        designationcode: Code[20];
    begin
        candidaterec.Reset();
        candidaterec.SetRange(application_status, candidaterec.application_status::Selected);
        if candidaterec.FindSet() then begin
            repeat
                interviewroundrec.Reset();
                interviewroundrec.SetRange(designation_code, candidaterec.candidate_applied_designation);
                if interviewroundrec.FindSet() then begin
                    repeat
                        interviewmasterrec.Init();
                        interviewmasterrec.Validate(candidate_code, candidaterec.candidate_code);
                        interviewmasterrec.designation_name := getdesignationname(candidaterec.candidate_applied_designation);
                        interviewmasterrec.interview_date := 0D;
                        interviewmasterrec.interview_time := 0T;
                        interviewmasterrec.interview_location := '';
                        interviewmasterrec.Status := interviewmasterrec.Status::Created;
                        interviewmasterrec.Insert(true);
                    until interviewroundrec.Next() = 0;
                end;
            until candidaterec.Next() = 0;
        end;
    end;

     
    Hope this is helpful :)

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,017 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans