web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
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();

}

I have the same question (0)
  • GirishS Profile Picture
    27,825 Moderator on at
    RE: Records should convert automatically to work order based on user input

    Hi Mohammed Rafia,

    Can you elaborate more on what type of class you are creating? I mean you are using Runbase or SysOperation framework?

    Thanks,

    Girish S.

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

    Am using RunbaseBatch

  • Suggested answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: Records should convert automatically to work order based on user input

    So, I am assuming you have already added the parameter to dialog. If yes, then you can get the parameter value by overriding the getFromDialog method. After getting the value to buffer you can use that buffer to perform calculation with dates.

    Refer to the below blog for adding parameters to dialog and getting values from the dialog.

    https://dynamics365musings.com/d365-batch-job/

    Thanks,

    Girish S.

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

    That everything is done, only the date validation how records are going to get created automatically based on parameter form which we give the value.

    sharing the code:

    class ERecurrenceForMaintenanceSchedule extends RunBaseBatch

    {

       DialogField                  dlgMaintenanceSchedule;

       EntAssetWorkOrderTypeRecId   workOrderType;

       DialogField                  dlgWorkOrderType;

       EntAssetWorkOrderTable       workOrderTable;

       EntAssetParameters           entAssetParameters = EntAssetParameters::find();

       public container pack()

       {

           return conNull();

       }

       public boolean unpack(container packedClass)

       {

           return true;

       }

       public Object dialog()

       {

           EntAssetWorkOrderTable workOrderTableCreated;

           Dialog dialog = super();

           dialog.caption( 'Maintenance plan');

           dlgWorkOrderType = dialog.addFieldValue(extendedTypeStr(EntAssetWorkOrderTypeRecId), entAssetParameters.PreventiveWorkOrderType);

           return dialog;

       }

       public boolean getFromDialog()

       {

           EntAssetWorkOrderTable workOrderTableCreated;

           boolean ret = super();

           return super();

       }

       public static void main(Args _args)

       {

           ERecurrenceForMaintenanceSchedule recurrenceForMaintenanceSchedule = new ERecurrenceForMaintenanceSchedule();

           if(recurrenceForMaintenanceSchedule.prompt())

           {

               recurrenceForMaintenanceSchedule.run();

           }

       }

       public EntAssetWorkOrderTypeRecId parmWorkOrderType1(EntAssetWorkOrderTypeRecId _workOrderType = workOrderType)

       {

           workOrderType = _workOrderType;

           return workOrderType;

       }

       public void run()

       {

           EntAssetObjectCalendarCreateWO createWO;

           EntAssetOBjectCalendar EntAssetObjectCalendar;

           Dialog      dialog;

           createWO = EntAssetObjectCalendarCreateWO::construct();

            while select EntAssetOBjectCalendar

               where EntAssetOBjectCalendar.WorkOrder == 0

             {

               createWO.addObjectCalendar(EntAssetOBjectCalendar);

             }

               createWO.parmCreateWo(EntAssetCreateWo::OneWoPerLine);

               createWO.parmWorkOrderType(entAssetParameters.PreventiveWorkOrderType);

               createWO.run();

       }

    }

  • GirishS Profile Picture
    27,825 Moderator 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.

  • Rafia Mohammed Profile Picture
    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
    27,825 Moderator 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
    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
    27,825 Moderator 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
    266 on at
    RE: Records should convert automatically to work order based on user input

    ok i will try and come back. Thank you.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,157

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 883 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 674 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans