Batch Job in Dynamics 365

In Dynamics 365 Batch job is created using RunBaseBatch. Below is the sample code to create batch job.

1:  class StudentBatchJob extends RunBaseBatch  
2:  {  
3:    server static StudentBatchJob construct()  
4:    {  
5:      return new StudentBatchJob();  
6:    }  
7:    public boolean canRunInNewSession()  
8:    {  
9:      return true;  
10:    }  
11:    public container pack()  
12:    {  
13:      return conNull();  
14:    }  
15:    public boolean unpack(container packedClass)  
16:    {  
17:      return true;  
18:    }  
19:    public static ClassDescription description()  
20:    {  
21:      return "StudentBatchJob";  
22:    }  
23:    public static void main(Args args)  
24:    {  
25:      StudentBatchJob batchProcess;  
26:      batchProcess = StudentBatchJob::construct();  
27:      if(batchProcess.prompt())  
28:      {  
29:        batchProcess.runOperation();  
30:      }  
31:    }  
32:    public void run()  
33:    {  
34:      #OCCRetryCount  
35:      try  
36:      {  
37:        StudentTable        studenetTable  
38:        int             studentCounter = 0;  
39:        ;  
40:        while select studentTable  
41:        {  
42:          ttsbegin;  
43:          studentTable.Status = "Enrolled";  
44:          studentTable.update();  
45:          ttscommitl  
46:        }  
47:        info(strFmt("Successfully processed %1 students.", counter));  
48:      }  
49:      catch (Exception::Deadlock)  
50:      {  
51:        retry;  
52:      }  
53:      catch (Exception::UpdateConflict)  
54:      {  
55:        if (appl.ttsLevel() == 0)  
56:        {  
57:          if (xSession::currentRetryCount() >= #RetryNum)  
58:          {  
59:            throw Exception::UpdateConflictNotRecovered;  
60:          }  
61:          else  
62:          {  
63:            retry;  
64:          }  
65:        }  
66:        else  
67:        {  
68:          throw Exception::UpdateConflict;  
69:        }  
70:      }  
71:    }  
72:  }  


Then create action menu item and set object type as class and object to StudentBatchJob.

Comments

Popular posts from this blog

X++ Get Start Date and End Date of Month

Dynamics AX 365 : The name does not denote a class, a table or an extended data type

Error while setting server report parameters. Error message: The permissions granted to user are insufficient for performing this operation. (rsAccessDenied)