Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Records should convert automatically to work order based on user input

(0) ShareShare
ReportReport
Posted on by 266

Hello everyone, i have a requirement where i need to create a batch job to create workorder automatically for form records. That is completely working fine. 

Now the additional requirement is to create one integer field in parameters form. If i give it as 2, now the records of (today + 2) records have to create work order automatically based one one field called expected start date. Sharing the code for previous requirement. If anyone is aware of the additional requirement like how we need to write the code.

Thanks in advance.

public void run()
{
EntAssetObjectCalendarCreateWO createWO;
EntAssetOBjectCalendar EntAssetObjectCalendar;
Dialog dialog;

EntAssetParameters entAssetParameters = EntAssetParameters::find();



createWO = EntAssetObjectCalendarCreateWO::construct();



while select EntAssetOBjectCalendar
where EntAssetOBjectCalendar.WorkOrder == 0


createWO.addObjectCalendar(EntAssetOBjectCalendar);

}
createWO.parmCreateWo(EntAssetCreateWo::OneWoPerLine);
createWO.parmWorkOrderType(entAssetParameters.PreventiveWorkOrderType);
createWO.run();

}

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Records should convert automatically to work order based on user input

    Yes, I got your point now. You need to get the data between date range.

    In that case you need to add date range to the query or select statement you have added to fetch 300 records.

    If it's a while select statement. 

    TransDate fromDate,toDate;
    
    fromDate = today();
    toDate = fromDate   parameterBuffer.IntegerValue;
    
    while select * from table
        {
           if(table.ExpectedStart >= fromDate && table.ExpectedStart <= todate)
           {
           //create work order
           }
        }

    Thanks,

    Girish S.

  • Rafia Mohammed Profile Picture
    Rafia Mohammed 266 on at
    RE: Records should convert automatically to work order based on user input

    You are partially right. not 15/1/2023. all the three

    13/1/2023

    14/1/2023

    15/1/2023 have to create the work order automatically.

    For example i have 300 records in the form, now i gave value as 30 in parameter. so from today till 11th  it checks the records are there for these dates. if lets say i have only 3 records available in that 30 days period. only that 3 records have to convert to work order.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Records should convert automatically to work order based on user input

    So, you are saying that if there are 3 lines with expected start date as

    1. 13/1/2023
    2. 14/1/2023
    3. 15/1/2023

    Now in the parameter form you have given 2 as value.

    So today() + 2 will give the result as 15/1/2023 - In that case only the 3rd one (15/1/2023) will be converted into work order.

    Is that you are asking?

    Thanks,

    Girish S.

  • Rafia Mohammed Profile Picture
    Rafia Mohammed 266 on at
    RE: Records should convert automatically to work order based on user input

    Hello Girish,

    I have used below code.

              if(countloop< entAssetParameters.ENoOfRecurrenceDays)

               {

                   createWO.addObjectCalendar(EntAssetOBjectCalendar);

                   countloop ++;

               }

               if(countloop == entAssetParameters.ENoOfRecurrenceDays)

               {

                   break;

               }

    Here if i use this code based on the number which i give in the parameter form, that many records are going to convert into workorder. But now what i need is, in expected start date if we have 100 records, if i give 5 in the parameter form. now today + if any records generated for this 5 days, that records only converted into work order. That means it is not based on records, its based on expectedstartdate.

  • Rafia Mohammed Profile Picture
    Rafia Mohammed 266 on at
    RE: Records should convert automatically to work order based on user input

    ok i will try and come back. Thank you.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Records should convert automatically to work order based on user input

    You can add this date calculation in the code where you are inserting records in work order table.

    Also, the integer field in the parameter form must be table level field, so that you can get the value.

    Refer to the below sample.

    //declare parameter table.
    ParameterTable parmTable;
    
    //your original code for work order insert will come here - After that you can write the below code.
    select firstonly * from parmTable;
    workOrderTable.ExpectedStartDate = today()   parmTable.IntegerField;
    WorkOrderTable.insert();
    
        
    

    Thanks,

    Girish S.

  • Rafia Mohammed Profile Picture
    Rafia Mohammed 266 on at
    RE: Records should convert automatically to work order based on user input

    Yes, i have one date field in main form where am going to create work orders.

    lets say i have 10 records in that form. In the parameter form, if i give value as 2.

    Now, today + 2 records have to convert it to workorder. For this i need a code.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Records should convert automatically to work order based on user input

    So, I am assuming you have written code to insert records in work order table.

    On the same code While inserting record in workorder table you can add a select statement to that table used in the parameter form and using that buffer you can get the integer value and add it with date value, right?

    Thanks,

    Girish S.

  • Rafia Mohammed Profile Picture
    Rafia Mohammed 266 on at
    RE: Records should convert automatically to work order based on user input

    I dont want to create any parameter, actually for every module we have one parameter form right! In that parameter form i have created one integer field, where if i give it as 6, today date plus 6 records have to create the workorder automatically. The above code is going to create the workorder for all the records, but i need to create the records based on input in the parameter form field. Thank you

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Records should convert automatically to work order based on user input

    You have already created one parameter - Similar to that you can create one new integer parameter - Get the values - Pass the values to parm method of EntAssetObjectCalendarCreateWO  class = You can use that parm method to add that with excepted start date.

    If still not clear with above suggestion, can you elaborate more about the date validations you are talking about?

    Thanks,

    Girish S.

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…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans