Showing posts with label IN. Show all posts
Showing posts with label IN. Show all posts

Wednesday, November 22, 2017

HOW TO GET DAY OF THE WEEK IN MICROSOFT DYNAMICS AX

HOW TO GET DAY OF THE WEEK IN MICROSOFT DYNAMICS AX 
static void dayOfWkExample(Args _arg)
{
    date d = today();
    int i;
    ;
    i = dayOfWk(d);
    print "Today's day of the week is " + int2Str(i);
    pause;
}

Tuesday, November 21, 2017

SAVE REPORT TO PDF FROM AX JOB CONTROLLER CLASS : VIKAS MEHTA HOW TO CALL A REPORT FROM JOB AND SAVE IT IN PDF

SAVE REPORT TO PDF FROM AX JOB CONTROLLER CLASS : VIKAS MEHTA
HOW TO CALL A REPORT FROM JOB AND SAVE IT IN PDF

public static void SaveReportToPDFFromController(Args _args)
{
    VIKSalesInvoiceFinanceController  salesInvoiceController;
    VIKSalesInvoiceFinanceContract    salesInvoiceContract;
    Args                    args = new Args();
    SrsReportRunImpl        srsReportRun;
    CustInvoiceJour         custInvoiceJour;
    SRSReportExecutionInfo  reportExecutionInfo;
    ReportName              reportName = "VIKSalesFinance.PrecisionDesign1";//PrecisionDesign1_backup
    #define.ReportName('VIKSalesFinance.PrecisionDesign1')
    ;
    //SRSReportExecutionInfo = new SRSReportExecutionInfo();d
    select firstOnly custInvoiceJour where custInvoiceJour.SalesId == "1234”;
    args.record(custInvoiceJour);

    salesInvoiceController = new VIKSalesInvoiceFinanceController();
    salesInvoiceController.parmReportName(reportName);

    reportExecutionInfo = salesInvoiceController.parmReportContract().parmReportExecutionInfo() as SrsPrintMgmtExecutionInfo;

    if (!reportExecutionInfo)
    {
       reportExecutionInfo = new SrsPrintMgmtExecutionInfo();
    }
    //reportExecutionInfo.parmOriginalDestinationFileName("c:\\SalesInvoice.pdf");
    salesInvoiceContract = salesInvoiceController.parmReportContract().parmRdpContract();
    salesInvoiceContract.parmReportCopyName('');
    salesInvoiceContract.parmTenderTypeId('21');
    salesInvoiceContract.parmInvoiceId(custInvoiceJour.InvoiceId);
    salesInvoiceContract.parmSalesId(custInvoiceJour.SalesId);

  //  salesInvoiceContract.
   // salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
   // salesInvoiceContract.parmInvoiceIdparm(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
    salesInvoiceController.parmArgs(args);
    salesInvoiceController.parmReportName(#ReportName);
    salesInvoiceController.parmDialogCaption("Sales Finance Invoice");
     args.parm(strFmt("Copy - 1"));

    srsReportRun = salesInvoiceController.parmReportRun() as SrsReportRunImpl;

    salesInvoiceController.parmReportRun(srsReportRun);
    salesInvoiceController.parmReportContract().parmReportExecutionInfo(reportExecutionInfo);
    salesInvoiceController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
    salesInvoiceController.parmReportContract().parmPrintSettings().overwriteFile(true);
    salesInvoiceController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    salesInvoiceController.parmReportContract().parmPrintSettings().fileName("c:\\test123\\SREPORT.pdf");
    salesInvoiceController.runReport();
}

static void SaveReportToPDFFromController(Args _args)
{
    SalesInvoiceController  salesInvoiceController;
    SalesInvoiceContract    salesInvoiceContract;
    SRSPrintDestinationSettings     settings;
    Args                    args = new Args();
    SrsReportRunImpl        srsReportRun;
    CustInvoiceJour         custInvoiceJour;
    ReportName              reportName = "SalesInvoice.Report";
    ;

    select firstOnly custInvoiceJour where custInvoiceJour.invoiceid == "sid";
    args.record(custInvoiceJour);

    salesInvoiceController = new SalesInvoiceController();
    salesInvoiceController.parmReportName(reportName);

    salesInvoiceContract = salesInvoiceController.parmReportContract().parmRdpContract();
    salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
  //  salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release
    salesInvoiceController.parmArgs(args);

    srsReportRun = salesInvoiceController.parmReportRun() as SrsReportRunImpl;

     salesInvoiceController.parmReportName(ssrsReportStr(VIKSalesFinance, PrecisionDesign1));
    // Use execution mode appropriate to your situation
  //  salesInvoiceController.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);
    // Suppress report dialog
    salesInvoiceController.parmShowDialog(false);

    salesInvoiceController.parmReportRun(srsReportRun);
    salesInvoiceController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
    salesInvoiceController.parmReportContract().parmPrintSettings().overwriteFile(true);
    salesInvoiceController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    salesInvoiceController.parmReportContract().parmPrintSettings().fileName("c:\\VIKAS\\sdc.pdf");


    settings = salesInvoiceController.parmReportContract().parmPrintSettings();
    settings.printMediumType(SRSPrintMediumType::File);
    settings.fileFormat(SRSReportFileFormat::PDF);
    settings.fileName(@'c:\\TEST\1234.pdf');

    salesInvoiceController.startOperation();
}



MULTISELECT VALUES FROM GRID AND EXECUTE ONE BY ONE :VIKAS MEHTA : MICROSOFT DYNAMICS AX x++ CODE MULTISELECT IN FORMS

MULTISELECT VALUES FROM GRID AND EXECUTE ONE BY ONE  :VIKAS MEHTA : MICROSOFT DYNAMICS AX x++ CODE MULTISELECT IN FORMS

Multiple select location warehouse ax x++ code helper class multiselect
Just write the below code on the clicked method event and the code will consider all the selected records in the grid and execute as per the requirement.
void clicked()
{
    InventLocation InventLocationLoc;
    MultiSelectionHelper helper = MultiSelectionHelper::construct();

    super();

    helper.parmDatasource(InventLocation_DS);

    InventLocationLoc = helper.getFirst();
    while (InventLocationLoc.RecId != 0)
    {
        select firstOnly selectWH where selectWH.InventLocationId == InventLocationLoc.InventLocationId
        ;
        if(!selectWH)
        {
            // your execution here
        }
        else
            info(strFmt("@VIK178",selectWH.InventLocationId));//warehouse already exist
        InventLocationLoc = helper.getNext();
    }

    info("warehouse assigned”);
}

Delete Excess Data in Table TaxDocumentJson from SQL command in Microsoft Dynamics AX

Delete Excess Data in Table TaxDocumentJson from SQL command in Microsoft Dynamics AX


Remove the excess data in TaxDocumentJson at in AX HQ. Please carry this out on a UAT environment. Once this is tested successfully, you can do the same steps on Production.
Run the following SQL query to remove excess data
DECLARE @Deleted_Rows INT;
SET @Deleted_Rows = 1;
WHILE (@Deleted_Rows > 0)
  BEGIN
   BEGIN TRANSACTION
   -- Delete some small number of rows at a time
     DELETE TOP (10) j from taxdocumentjson j
inner join TaxDocumentRow r on r.TAXDOCUMENTJSON = j.ID;
SET @Deleted_Rows = @@ROWCOUNT;   
   COMMIT TRANSACTION
   CHECKPOINT -- for simple recovery model
END
You can count the number of the records required to be cleaned via another session to understand the progress
Select count(*) from taxdocumentjson j inner join TaxDocumentRow r on r.TAXDOCUMENTJSON = j.ID;

THE FIELD WITH ID '0' DOES NOT EXIST IN TABLE - SOLUTION :DYNAMICS AX X++ CODE

THE FIELD WITH ID '0' DOES NOT EXIST IN TABLE - SOLUTION :DYNAMICS AX X++ CODE 
ISSUE :
THE FIELD WITH ID '0' DOES NOT EXIST IN TABLE - SOLUTION.


SOLUTION:
YOU WILL GET THIS ERROR WHEN ONE OF THE FIELDS IS NOT MAPPED PROPERLY MOSTLY IN THE MAPS BEING USED.

HOW TO CONNECT TO SQL FROM AX AND UPDATE HOW TO CONNECT TO EXTERNAL DATABASE FROM AX HOW TO UPDATE RECORDS IN SQL FROM AX : DYNAMICS AX X++ CODE

HOW TO CONNECT TO SQL FROM AX AND UPDATE
HOW TO CONNECT TO EXTERNAL DATABASE FROM AX
HOW TO UPDATE RECORDS IN SQL FROM AX

1) fIRST CREATE AN ODBC CONNECTION FROM THE SYSTEM TO CONNECT TO THE REQUIRED DATABASES.
// X++, Main method in a class.
static public void Main(Args _args)
{
    LoginProperty loginProperty;
    OdbcConnection odbcConnection;
    Statement statement;
    ResultSet resultSet;
    str sql, criteria;
    SqlStatementExecutePermission perm;
    ;

    // Set the information on the ODBC.
    loginProperty = new LoginProperty();
    loginProperty.setDSN("dsnName");
    loginProperty.setDatabase("databaseName");

    //Create a connection to external database.
    odbcConnection = new OdbcConnection(loginProperty);

    if (odbcConnection)
    {
        sql = "SELECT * FROM MYTABLE WHERE FIELD = "
            + criteria
            + " ORDER BY FIELD1, FIELD2 ASC ;";

        //Assert permission for executing the sql string.
        perm = new SqlStatementExecutePermission(sql);
        perm.assert();

        //Prepare the sql statement.
        statement = odbcConnection.createStatement();
        resultSet = statement.executeQuery(sql);

        //Cause the sql statement to run,
        //then loop through each row in the result.
        while (resultSet.next())
        {
            //It is not possible to get field 3 and then 1.
            //Always get fields in numerical order, such as 1 then 2 the 3 etc.
            print resultSet.getString(1);
            print resultSet.getString(3);
        }

        //Close the connection.
        resultSet.close();
        statement.close();
    }
    else
    {
        error("Failed to log on to the database through ODBC.");
    }
}

HOW TO ADD RANGE USING EXPRESSIONS IN QUERY (strFmt('((%1.%2 ==) IN MICROSOFT DYNAMICS AX X++ CODE

HOW TO ADD RANGE USING EXPRESSIONS IN QUERY  strFmt('((%1.%2 ==
IN MICROSOFT DYNAMICS AX X++ CODE

static void AddRangeToQuery(Args _args)
{
    Query q = new Query();  // Create a new query.
    QueryRun qr;
    CustTable ct;
    QueryBuildDataSource qbr1;
    str strTemp;
    ;

    // Add a single datasource.
    qbr1 = q.addDataSource(tablenum(CustTable));
    // Name the datasource 'Customer'.
    qbr1.name("Customer");

    // Create a range value that designates an "OR" query like:
    // customer.AccountNum == "4000" || Customer.CreditMax > 2500.

    // Add the range to the query data source.
    qbr1.addRange(fieldNum(CustTable, AccountNum)).value(
    strFmt('((%1.%2 == "4000") || (%1.%3 > 2500))',
        qbr1.name(),
        fieldStr(CustTable, AccountNum),
        fieldStr(CustTable, CreditMax)));

    // Print the data source.
    print qbr1.toString();
    info(qbr1.toString());

    // Run the query and print the results.
    qr = new QueryRun(q);

    while (qr.next())
    {
        if (qr.changedNo(1))
        {
            ct = qr.getNo(1);
            strTemp = strFmt("%1 , %2", ct.AccountNum, ct.CreditMax);
            print strTemp;
            info(strTemp);
        }
    }
    pause;
}

CREATE ADD MODIFY AND DELETE AX x++ QUERY IN MICROSOFT DYNAMICS AX

CREATE ADD MODIFY AND DELETE AX x++ QUERY IN DYNAMICS AX
Static void CreateQueryJob(Args _args)
{
    TreeNode                treeNodeObj;
    Query                   queryObj; // Extends TreeNode class.
    QueryBuildDataSource    qbds;
    QueryBuildRange         qbr;
    QueryRun                qr;
    CustTable               xrecCustTable;
    str                     queryName = "MyQuery1";
    
    // Macro.
    #AOT

    // Delete the query from the AOT, if the query exists.
    treeNodeObj = TreeNode::findNode(#QueriesPath);
    treeNodeObj = treeNodeObj.AOTfindChild(queryName);
    if (treeNodeObj) { treeNodeObj.AOTdelete(); }

    // Add the query to the AOT.
    treeNodeObj = TreeNode::findNode(#QueriesPath);
    treeNodeObj.AOTadd(queryName);
    queryObj = treeNodeObj.AOTfindChild(queryName);
    
    // Further define the query.
    qbds  = queryObj.addDataSource(tablenum(CustTable));
    qbr   = qbds.addRange(fieldnum(CustTable, DlvMode));
    qbr.value(">10");

    // Compile the query.
    queryObj.AOTcompile(1);
    queryObj.AOTsave();

    // Run the query.
    qr = new QueryRun("MyQuery1");
    while ( qr.next() )
    {
        xrecCustTable = qr.GetNo(1); // 1 means first data source.
        Global::info(strFmt("%1 , %2",
            xrecCustTable.AccountNum, xrecCustTable.DlvMode));
    }        

    // Delete the query from the AOT.
    treeNodeObj = TreeNode::findNode(#QueriesPath);
    treeNodeObj = treeNodeObj.AOTfindChild(queryName);
    treeNodeObj.AOTdelete();
}

CREATE DYNAMIC QUERY IN AX X++ CODE ON THE FLY FILTER: DYNAMICS AX X++ CODE


CREATE DYNAMIC QUERY IN AX X++ CODE WITH FILTER

public void qUERYdYNAMICS()
{
    Query q;
    QueryRun qr;
    QueryBuildDataSource qbd;
    QueryBuildRange qbr;

    q = new Query();
    qbd = q.addDataSource(TableNum(CustTable));

    qbr = qbd.addRange(FieldNum(CustTable, AccountNum));
    qbr.value(">=4000"); // Default operator is ==.

    qbr = qbd.addRange(FieldNum(CustTable, AccountNum));
    qbr.value("<=4022");

    qbd.addSortField(FieldNum(CustTable, DlvMode));

    qr = new QueryRun(q);
    qr.prompt();

    pause;
}

JOB X++ MICROSOFT AX PULL /SAVE DATA IN CSV FILES :WINAPI FILES : DYNAMICS AX X++ CODE

JOB X++ MICROSOFT AX DATA IN CSV FILES WINAPI

static void VIK_VM_SalesLineToCSVTable(Args _args)
{
    PurchLine       purchLine;
    SalesLine       salesline;
    Query q;
    QueryBuildDataSource qbds;
    QueryBuildRange qbr;
    QueryRun qr;
    CommaIO commaIO;
    FileName fileName;
    InventTable inventTable;
    salestable  salestable;
    ;
    fileName = "C:\\Vicky\\" + "SAlesline_serial_newD" + ".txt"; //Destination of the file
    commaIO = new CommaIO(fileName,'W');

    commaIO.write("Sales Id", "Custaccount","Itemid","SalesStatus", "Serial Number"); //Header of the CSV File

    //Loop to insert values in the csv from the table
    while select salesline
            join salestable where SalesLine.salesid == SalesTable.salesid && salestable.salesstatus == SalesStatus::Backorder
                         //  && salesline.SalesId like "%SOD%"//(salestable.salesstatus == SalesStatus::Delivered || salestable.salesstatus == SalesStatus::Backorder)//&& salestable.SalesId like "%SOD%"
    {
    commaIO.write(salesline.SalesId, salestable.CustAccount, SalesLine.ItemId,SalesTable.SalesStatus,SalesLine.inventDim().inventSerialId);


    }
    WINAPI::shellExecute(fileName);
    info("DONE.");
}


Friday, June 16, 2017

Extended Data Types (EDTs) : EDT IN AX: MICROSOFT DYNAMICS 365:DYNAMICS AX 2012

Extended Data Types (EDTs) 

Extended data types (EDTs) are user-defined types, based on the primitive data types boolean, integer, real, string, and date, and the composite type container. You can also base EDTs on other EDTs.
This feature is not implemented as a language construct. EDTs are defined in the Application Object Tree (AOT).
An EDT is a primitive data type or container with a supplementary name and some additional properties. For example, you could create a new EDT called Name and base it on a string. Thereafter you can use the new EDT in variable and field declarations in the development environment.

Benefits of EDTs

The benefits of EDTs are as follows:
·         Code is easier to read because variables have a meaningful data type. For example, Name instead of string.
·         The properties you set for an EDT are used by all instances of that type, which reduces work and promotes consistency. For example, account numbers (AccountNum data type) have the same properties throughout the system.
·         You can create hierarchies of EDTs, inheriting the properties that are appropriate from the parent and changing the other properties. For example, the ItemCode data type is used as the basis for the MarkupItemCode and PriceDiscItemCode data types.

Declaration of EDT Variables

In the AOT, the Data Dictionary > Extended Data Types node is used to create EDTs. The range of an EDT is identical to that of the base type it is based on. When you declare a variable in X++, use the syntax shown in the following table.
Extended declaration
=
Extendedtype Variable { , Variable } ;
Variable
=
Identifier [ option ]
Option
=
arrayoptions | initialization
where Extendedtype is the name of the extended data type in the AOT.
X++
// A UserGroupID (integer) variable is declared and initialized to 1.
UserGroupID groupID = 1;
 
// An Amount (real) variable is declared.
Amount currency;

Automatic Conversion


EDTs are standard data types, but with a specific name and additional properties. EDTs undergo the same value and type conversions as do the standard data types they are based on.

Thursday, June 8, 2017

CALL DIFFERENT REPORT DESIGN IN AX 2012 MICROSOFT DYNAMICS

AX 2012 SSRS REPORT DESIGN 
Go to main method in controller class and write below code to call the report.

   SSRSRPTController   controller; 
   controller = new SSRSRPTController(); 
   controller.parmArgs(args); 
   controller.parmReportName(ssrsReportStr(SALESREPORT, DESIGN1)); 
   controller.parmShowDialog(true); 

   controller.startOperation()  

How to Upload License in Microsoft Dynamics AX 2012 :MICROSOFT DYNAMICS AX 2012

How to Upload License in Microsoft Dynamics AX 2012 :MICROSOFT DYNAMICS AX 2012

Go To System administration > Setup > Licensing > License information.
Then Click Load license file to import the license codes from a file and select license file.
Click  OK button.

This will also Synchronize the database.


HOW TO REMOVE BLANK SPACES IN AX: AX 2012 MICROSOFT DYNAMICS AX 2012 :AX 2009

HOW TO REMOVE BLANK SPACES IN AX: AX 2012 

MICROSOFT DYNAMICS AX 2012 :AX 2009


Just replace the code with the below syntax.

strRTrim(strLTrim(Dirpartytable.Name));  

STANDARD CUBE IN MICROSOFT DYNAMICS AX 2012 R3 : CUBES IN AX 2012 R3 MICROSOFT

STANDARD CUBE IN MICROSOFT DYNAMICS AX 2012 R3

1 ACCOUNTS PAYABLE CUBE (VENDCUBE)
2 ACCOUNTS RECEIVABLE CUBE (CUSTCUBE)
3 BUDGET CONTROL CUBE (BUDGETCONTROLCUBE)
4 BUDGET PLAN CUBE (BUDGETPLANCUBE)
5 DEMAND FORECAST ACCURACY CUBE (REQDEMPLANACCURACYCUBE)
6 DEMAND FORECAST CUBE (REQDEMANDPLANNINGCUBE)
7 ENVIRONMENTAL SUSTAINABILITY CUBE (EMSCUBE)
8 EXPENSE MANAGEMENT CUBE (TRVCUBE)
9 GENERAL LEDGER CUBE (LEDGERCUBE)
10 HUMAN RESOURCES CUBE (HUMANRESOURCECUBE)
11 INVENTORY VALUE CUBE (INVENTVALUECUBE)
12 PAYROLL CUBE (PAYROLLCUBE)
13 PRODUCTION CUBE (PRODCUBE)
14 PROFIT TAX TOTALS CUBE (RTAX25REGISTERS)
15 PROJECT ACCOUNTING CUBE (PROJCUBE)
16 PURCHASE CUBE (PURCHCUBE)
17 RETAIL CUBE (RETAILCUBE)
18 SALES AND MARKETING CUBE (SMMSALESMARKETINGCUBE)
19 SALES CUBE (SALESCUBE)
20 WORKFLOW CUBE (WORKFLOWCUBE)

Reserved words in Ax 2012 : MICROSOFT DYNAMICS AX 2012 :MICROSOFT DYNAMICS AX 2009: RESERVED WORDS

Reserved words in Ax 2012

1
abstract
54
implements
2
anytype
55
index
3
as
56
insert_recordset
4
asc
57
int
5
at
58
int64
6
avg
59
interface
7
break
60
is
8
breakpoint
61
join
9
by
62
like
10
byRef
63
maxOf
11
case
64
minOf
12
catch
65
mod
13
changeCompany
66
new
14
class
67
next
15
client
68
noFetch
16
container
69
notExists
17
continue
70
null
18
count
71
optimisticLock
19
crossCompany
72
order
20
date
73
outer
21
default
74
pause
22
delegate
75
pessimisticLock
23
delete_from
76
print
24
desc
77
private
25
display
78
protected
26
div
79
public
27
do
80
real
28
edit
81
repeatableRead
29
else
82
retry
30
eventhandler
83
return
31
exists
84
reverse
32
extends
85
select
33
FALSE
86
server
34
final
87
setting
35
firstFast
88
static
36
firstOnly
89
str
37
firstOnly1
90
sum
38
firstOnly10
91
super
39
firstOnly100
92
switch
40
firstOnly1000
93
tableLock
41
flush
94
throw
42
for
95
TRUE
43
forceLiterals
96
try
44
forceNestedLoop
97
ttsAbort
45
forcePlaceholders
98
ttsBegin
46
forceSelectOrder
99
ttsCommit
47
forUpdate
100
unchecked
48
from
101
update_recordSet
49
generateonly
102
utcDateTime
50
group
103
validTimeState
51
guid
104
void
52
hint
105
where
53
if
106
while


107
window
Related Posts Plugin for WordPress, Blogger...