web
You’re offline. This is a read only version of the page.
close
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...
Answered

SetRange for Option field

(0) ShareShare
ReportReport
Posted on by 700

Hi All,

I have one option field on 'Job Card' i.e. Feedback Type.

I have to calculate the no. of jobs for which Feedback Type is 'Excellent' and divide the count by total no. of Jobs.

Total no. of jobs has been calculated and SetRange has been put on Feedback Type.

But, I am not getting how to get the no of jobs for which Feedback Type is 'Excellent'.

Please suggest the solution.

Below is the block of code :

    Rec_Job.Reset();
                Rec_Job.SetRange(Feedbacktype, Feedbacktype::Excellent);
                Total_No_Of_Jobs := Job.Count;
                if Rec_Job.FindSet() then
                    repeat
                        Excellent := Feedbacktype / Total_No_Of_Jobs;                      Excellent is the variable to store the calculated value.
                    until
                        Rec_Job.Next = 0;
I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,005 Super User 2025 Season 2 on at

    May be I am not following your requirement but Total_No_Of_Jobs already has excellent projects count. what else are you looking for?

  • Dynamics 365 Business Central Profile Picture
    700 on at

    Hi Mohana,

    I have to calculate the no. of jobs for which Feedback Type is 'Excellent' and divide the count by Total No. of Jobs.

    What modification needs to be done in the code to achieve this ?

  • Suggested answer
    gert@lynge.org Profile Picture
    on at
    The filter is also influenzing the number returned from Job.Count and you probably would also like to catch the possible division by zero corner case, so you need to do something like this:
        Rec_Job.Reset();
                    Total_No_Of_Jobs := Job.Count;
                    if Total_No_of_Jobs > 0 then begin
                    Rec_Job.SetRange(Feedbacktype, Feedbacktype::Excellent);
                        Excellent := Job.Count / Total_No_Of_Jobs;
                   end else
                    Excellent := 0;
  • Dynamics 365 Business Central Profile Picture
    700 on at

    Hi Gert,

    I tried this code.

    In my case, Job.count is 1 and Total_No_Of_Jobs is 4.

    But, the value displayed is 1.

  • Suggested answer
    Mohana Yadav Profile Picture
    61,005 Super User 2025 Season 2 on at

    is Excellent a decimal type variable or integer?

  • Verified answer
    gert@lynge.org Profile Picture
    on at

    Sorry, that is what happens when you write code outside NAV/BC and don't test it in NAV/BC :-)

    I didn't spot you had two Job record variables. Try with just one.

    Try:

                    Job.Reset();
                    Total_No_Of_Jobs := Job.Count;
                    if Total_No_of_Jobs > 0 then begin
                    Job.SetRange(Feedbacktype, Feedbacktype::Excellent);
                        Excellent := Job.Count / Total_No_Of_Jobs;
                   end else
                    Excellent := 0;
  • Dynamics 365 Business Central Profile Picture
    700 on at

    Thanks Gert, it works.

    But I have to filter the records based on Customer Name also i.e. for a specific customer, the value of Feedback Type should be shown which is tagged to that customer.

    How to put this filter on the code ?

  • Dynamics 365 Business Central Profile Picture
    700 on at

    customer-performance.png

    For 'School of Fine Art' customer only 'Excellent' feedback type is given, not others.

    Others are for other customers.

    I have to display only the feedback type linked to that particular customer.

    Please help !

  • Suggested answer
    gert@lynge.org Profile Picture
    on at

    Just put any other filters just after the Job.Reset(); line.

  • Dynamics 365 Business Central Profile Picture
    700 on at

    Rec_Job.Reset();

                   Rec_Job.SetFilter("Bill-to Name", "Bill-to Name");

                   Total_No_Of_Jobs := Rec_Job.Count;

                   if Total_No_of_Jobs > 0 then begin

                       Rec_Job.SetRange(Feedbacktype, Feedbacktype::Excellent);

                       Excellent := Rec_Job.Count / Total_No_Of_Jobs;

                   end else

                       Excellent := 0;

    Please check if it is correct !

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans