Showing posts with label AS. Show all posts
Showing posts with label AS. Show all posts

Friday, June 16, 2017

Tables as Data Types :MICROSOFT DYNAMICS 365:DYNAMICS AX 2012 X++

Tables as Data Types

All tables, which are created in MorphX by using the Application Object Tree (AOT), can be treated like class definitions (at least in all practical aspects) in the X++ programming language.
You can address fields and create methods on tables. The methods can be invoked on instances of the table.
To manipulate (read, update, insert, and delete) records in tables, you must declare at least one table variable, which can hold the record in focus.
Here are a few important differences between tables and objects:
·         You cannot allocate space for table variables—it is done implicitly.
·         Fields in table variables are public—you can reference them anywhere.
·         Fields in table variables can be referenced with expressions.

Scope of Table Variables

Table variables are declared on the basis of the data dictionary in MorphX; that is, on the basis of the tables, which are declared in the AOT. In most respects, table variables can be considered objects. Contrary to objects, they are not allocated explicitly. Only a variable declaration is required.
All tables are compatible with the Common table in the same way that all objects are compatible with the Object class. Table variables, which are declared as common buffers, can be used to hold data from any table. You cannot access tables without table variables.

Declaration of Table Variables

The principles for declaring table variables and objects are the same except for the allocation of space.
Table variable declaration
= ( tablename | common ) Variable { , Variable } ;
public void myMethod()
{
    // Declares and allocates space for one CustTable record
    CustTable custTable;
}
Note
It is a best practice to use the name of the table as the name of the variable, but with an initial lowercase letter.

Referencing Table Variables

The syntax for referencing fields in a table variable is:
RefTableVariable = Tablevariable.[ ( expression ) | fieldname ]
The most widely used field reference is Tablevariable.Fieldname, for example custTable.AccountNo.
public void printAccountNo();
{
    CustTable custTable;
    ;
    print custTable.AccountNo;
}
The syntax, however, also allows various possibilities for referencing fields in records, for example by using the TableName.(FieldId) syntax. The following example prints the contents of the fields in the current record in the Customer table.
X++
public void printCust()
{
    int i, n, k;
    CustTable custTable;
    DictTable dictTable;
    ;
 
    dictTable = new DictTable(custTable.TableId);
    n = dictTable.fieldCnt();
 
    print "Number of fields in table: ", n;
    for(i=1; i<=n; i++)
    {
        k = dictTable.fieldCnt2Id(i);
        print "The ", dictTable.fieldName(k), 
            " field with Id=",k, " contains '", 
            custTable.(k), "'";
        pause;
    }
}
Note
The previous example uses the fieldCnt and fieldCnt2Id methods. The fieldCnt method counts the number of fields in a table, while fieldCnt2Id returns the ID for a field number. For example, you can use the fieldCnt2Id method to find out that field number 6 in a table has the ID 54. It is necessary to perform this conversion because it is not guaranteed that the IDs of the fields in a table are consecutive.

Automatic Conversion


There is no automatic conversion, but table variables that are declared as Common can hold data from any table.

Saturday, October 15, 2016

CREATE A BATCH JOB IN AX 2012 AND SEND THE REPORT AS EMAIL ATTACHMENT VIA BATCH JOB SCHEDULER

STEPS TO CREATE A BATCH JOB IN AX 2012  AND SEND THE REPORT AS EMAIL ATTACHMENT THROUGH BATCH JOB.

This document covers the creation of batch job for Customers Report as an example.
Go to Accounts Receivable > Reports > Customer > Customers Report
Select the Customers range using select button in the customers report dialog box


Click on Destinations button to specify the print destination of the report
Various Print Destinations are available in Print Destination Settings
Print destination as screen is not allowed for a report runs as batch.
Select the E-mail and enter the email addresses as shown in the screen shot below. Select the File format from the different file format options available in the lookup.

Click OK after selecting Print Destination.
In the Customers Dialog box Click on Batch Tab.


Select the Batch processing check box.

Set the following options:
Task Description – Enter a description for the job.

Batch group - Assign the job to a batch group.
Batch groups are designed to enable you to run specific types of jobs on a specific batch server, or to run jobs on batch servers that are available at specific times. Batch groups are created by system administrators.
Private – Select this check box to restrict other users from processing your batch job. A private job can be run only by the user who submitted it, from the Set up batch processing form, and only on the computer where the user is logged on.

Click Recurrence to configure a batch job to recur on a specific schedule.


Time zone: Select the time zone.
Starting time: Enter the time that the batch job starts at.
Starting date:  Enter the date that the batch job starts at.
No end date: select this option to make the job run forever.
End after: Select this option to make the batch job stop after some occurrences.
Count:   Enter the specific number of recurrences.
End by:  Select this option to make the batch job stop at specific date
End date: Enter the last date of the job run.
Minutes:  select this option to make the job run for every specified number of minutes.
Enter the number of minutes in the Count Field.
Hours:  select this option to make the job run for every specified number of hours.
Enter the number of hours in the Count Field.
Days: select this option to make the job run for every specified number of days.
Enter the number of days in the Per field.
To run the batch job daily from Monday to Friday, click Every weekday
Weeks: select this option to make the job run for every fixed weekly intervals.
Enter the number of weeks in the Fixed weekly interval field, and then select the days on which you want the job to run.
For example, if you type 2 in the Fixed weekly interval field, and then select Monday and Wednesday, the batch job runs every two weeks on Monday and Wednesday.

Months:  select this option to make the job run for every fixed monthly intervals.
To set the day of the month and the frequency of the batch job, select Repeat a specific day by a fixed interval.
For example, if you enter 1 in the Day field and 3 in the Per field, the batch job runs on the first of the month for every three months.
To set a particular day of the week and the frequency of the batch job, select Repeat a specific weekday by a fixed interval.
For example, if you select Last in the Week field and Friday in the Weekdays field, and then enter 6 in the Per field, the batch job runs for every six months on the last Friday of the month.

Years:  select this option to make the job run for every year.
Select Repeat once a year or Repeat a specific weekday a year, and then set the starting date.
For example, if you select First in the Week field, Monday in the Weekdays field, and June in the Month field, the batch job runs for every year on the first Monday in June.



Click Alerts button.





Configure alerts for a batch job as shown in the following screen and Click OK.


Once the recurrence and alerts configuration is done click OK on the Customers Report dialog box.







The below message box pops up after the batch is created and added to queue.



Presetup’s needs to be done before sending the report as Email attachment
Related Posts Plugin for WordPress, Blogger...