Tuesday, 14 August 2018

Get a list of Security Roles with Duties from Dynamics AX using code X++


Following code can be used to obtain a list of all security roles along with the associated duties from Dynamics AX using X++ code:

static void JZS_ExtractRoleswithDuties(Args _args)
{

    CommaIO                       commaIO;
    FileName                        fileName;
    InventTable                     inventTable;
    SecurityRole            SecurityRole;
    SecurityRoleTaskGrant grantTable;
    str DutyName;
    SecurityTask            securityTask, securityTaskDef;
    ;

    fileName       = WINAPI::getTempPath() + "Security Roles" + ".csv";
    commaIO      = new CommaIO(fileName,'W');


    commaIO.write("Security Role","Description","Duty name","Duty AOT name","Duty description");

    while select SecurityRole order by Name
        join grantTable where grantTable.SecurityRole == SecurityRole.RecId
        join securityTask where securityTask.RecId == grantTable.SecurityTask
        && SecurityTask.Type == SecurityTaskType::Duty

    {
       select securityTaskDef where securityTaskDef.RecId == securityTask.RecId;
     
       DutyName = securityTaskDef.Name ;
       // info(strFmt("%1", DutyName ));

        commaIO.write(SecurityRole.Name+"("+SecurityRole.AotName+")", SecurityRole.Description, securityTaskDef.Name ,securityTaskDef.AotName, securityTaskDef.Description);
    }

    WINAPI::shellExecute(fileName);
}

Tuesday, 12 June 2018

Get customer contact Information by Type and Purpose

Following job can be used to reterieve customer contact information by type (email/telephone) and purpose (Business/Invoice)

static void JS_CustomerContactbyTypePurpose(Args _args)
{
    CustTable                   custTable = CustTable::find("003764");
    LogisticsElectronicAddress   electronicAddresslocal;
 
    LogisticsElectronicAddress getelectronicAddress(CustAccount                             CustAccount, // Customer Account
                                                    LogisticsElectronicAddressMethodType    contactType = LogisticsElectronicAddressMethodType::Phone,
                                                    LogisticsLocationRoleType               purpose = LogisticsLocationRoleType::Invoice)
    {
        LogisticsLocation               parentLocation;
        DirPartyLocation                dirPartyLocation;
        LogisticsElectronicAddress      electronicAddress;
        LogisticsElectronicAddressRole  electronicAddressRole;
        LogisticsLocationRole           locationRole;
        custTable                       _custtable;
         select _custtable
            where _custtable.accountNum == CustAccount// Specify customer account here
            join dirPartyLocation
            where dirPartyLocation.Party == custTable.Party
            join parentLocation
            where dirPartyLocation.Location == parentLocation.RecId
            join electronicAddress
            where electronicAddress.Location == parentLocation.RecId
            && electronicAddress.Type == contactType
            join electronicAddressRole
            where electronicAddressRole.ElectronicAddress == electronicAddress.RecId
            join locationRole
            where electronicAddressRole.LocationRole == locationRole.RecId
            && locationRole.Type == purpose;
        {
           return electronicAddress;
        }
    }
 
    electronicAddresslocal = getelectronicAddress(custTable.AccountNum, LogisticsElectronicAddressMethodType::Phone, LogisticsLocationRoleType::Invoice);
    info(strFmt("Customer: %1, Description: %2, Information %3",  custTable.AccountNum, electronicAddresslocal.Description, electronicAddresslocal.Locator));
 
    electronicAddresslocal = getelectronicAddress(custTable.AccountNum, LogisticsElectronicAddressMethodType::Email, LogisticsLocationRoleType::Invoice);
    info(strFmt("Customer: %1, Description: %2, Information %3",  custTable.AccountNum, electronicAddresslocal.Description, electronicAddresslocal.Locator));

}

Tuesday, 2 June 2015

Post Sales Invoice by X++ with selected sales line


Sometimes we need to post sales invoice with selected lines below is the code:

SalesFormLetter salesFormLetter =  SalesFormLetter::construct(DocumentStatus::Invoice);
   SalesTable salesTAble;
   SalesParmLine parmLine;
   SalesLine salesline;
   salesTable = SalesTable::find('AU-027333');
   salesFormLetter.salesTable(salesTAble);
   salesFormLetter.transDate (systemDateGet());
   salesFormLetter.specQty (SalesUpdate::All);
   //If you want proforma you can enable the code
   salesFormLetter.proforma (true);
   salesFormLetter.printFormLetter (true);
   salesFormLetter.createParmUpdateFromParmUpdateRecord(salesFormLetter.salesParmUpdate());
   salesFormLetter.initParmSalesTable(salesTAble);
   salesFormLetter.initParameters(salesFormLetter.salesParmUpdate(),Printout::After);
   salesFormLetter.initLinesQuery();
   while select forUpdate parmLine where parmLine.ParmId == salesFormLetter.parmId()
   {
       salesLine = salesline::findInventTransId(parmLine.InventTransId);      
       if (salesline.ShippingDateRequested > today())
       {
           ttsBegin;
           parmLine.delete();
           ttsCommit;
       }
   }

Saturday, 4 May 2013

Insert text qualifier while Importing CSV file by X++

Hi, 
When importing CSV file by X++ code in Dynamics AX we may encounter a situation when we need to eliminate extra string from master data . That string may be in form of an extra comma or | or speech mark or any other symbol. To achieve this goal and clean maser data i have written a job. Good Luck 


static void Job669(Args _args)

{
    str         _text,note,cleanText;
    int         charpos,s1,s2,i,more;
    int         x;
   char        RepChar = ',';
   char        RepCharWith = ' ';
    str text(str text)
    {
        s1 = strFind(text,'"',1,strlen(text));
        s2 = strFind(text,'"',s1,strlen(text));
        for (i=s1;i<s2+4;i++)
        {
            charpos = strScan(text,',',s1,s2);
            text = strpoke(text,' ',charpos);
            s1 = strFind(text,'"',1,strlen(text));
            s2 = strFind(text,'"',s1+1,strlen(text));
            charpos = strScan(text,',',s1,s2);
            if (charpos > s2)
            {
                break;
            }
        }
        if (s1 || s2)
        {
            text = strdel(text,s1,1);
            text = strdel(text,s2-1,1);
        }
        return text;
    }
    ;
    more = 1;
    _text = 'AXT001,"House,42,ENF",Enfield,"U,K"';
    while( more !=0)
    {
        _text = text(_text);
         more = strFind(_Text,'"',1,strlen(_Text));
    }
    info(_text);
}

Sunday, 24 February 2013

Thursday, 3 January 2013

Creating a View in Dynamics AX

Hello Everyone, In this blog i gonna show you how to create a simple view in Dynamics AX that consists of ItemID, Name, Sales ID, Customer Group and Customer Name using the following steps:
1. Right-click on the Views node and select New View. A new view will be created. You can open its properties by right-clicking and selecting Properties. 

2. Change the name of the view to InventSalesCust and give it a label that describes the contents of the view.  

3. The views can actually use queries that have already been created as a base for the data selection. This is done in the Properties of the view by choosing the query from the Query property. However, in our example, we will create the view from scratch. 

4. Under the Metadata node, right-click on the Data Sources node and select New Data Source 

5. Select the newly created data source and enter InventTable in the table property. The name of the data source will automatically change to InventTable_1, which is normal. 

6. Under the InventTable data source, find the Data Sources node, right-click on it, and select New Data Source. This time, we want to use the SalesLine table so change the table property to SalesLine. Also change the relations property to Yes in order to get the link between the two tables active in the view. 

7. Do the same to add the CustTable as a child data source to the SalesLine.

8. The next step is to define the fields that should be made available when this query is executed. Simply drag fields you need to use in the view from the InventTable_1,SalesLine_1, and CustTable_1 data source and drop them onto the Fields node. 

9. You should now have a view that looks like the following screenshot:

Sunday, 15 July 2012

Delete all the transactions from Dynamics AX

‎ Hi, to delete all the transactions from Dynamics AX 2009-12 please take the following steps .
1- go to AOT
2-open the classes
3-search on SysDatabaseTransDelete class
4- right click on the this class
5-choose open
6-click yes on the message box appear to you
7-info will appear to you "operation completed"

Saturday, 30 June 2012

Microsoft Dynamics Ax 2009 web project template is missing in visual studio 2008



If you cant see the Dynamics AX Web Project template in Visual Studio, please go through the following list:


If a user can see Microsoft Dynamics Ax Web Project template it’s because in his/her profile on system the template is available. In general the template is located on a windows 2003 server at C:\Documents and Settings\[user id ]\My Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer\CSharp\ AxWebProject.zip


To make Microsoft Dynamics Ax Web Project template available for other users copy the Templates folder from the user who can see template and paste it to other users’ profile It assumed that your templates are available in the default located as mentioned in above path

1.    Go to C:\Documents and Settings\[user id ]\My Documents\Visual Studio 2008\

2.    Copy Templates folder

3.    Open the other users’ profile and go to C:\Documents and Settings\[user id ]\My Documents\Visual Studio 2008\

4.    Paste the Templates folder. If system says to overwrite it click on yes option.

5.    You may need to refresh Visual Studios cache of templates after copying them:

6.    Open the Visual Studio command prompt (Start \ Programs \ Microsoft Visual Studio 2008 \ Visual Studio Tools \ Visual Studio 2008 Command Prompt) and type devenv /installvstemplates.

7.    If you still don't see the template, remember that you need to select C# as your project programming language before it shows up.
If you can see the template but can't connect to the AX AOS from Visual Studio check the following:

1.    Check that .NET Business Connector has been correctly installed and that the configuration points to the correct AOS instance.


2.    Check that the user you run Visual Studio with, has login and proper development permissions in AX.
 

3.    Check that the "Dynamics AX Enterprise Portal Tools" Add-in is correctly installed in Visual Studio. Open Visual Studio / Tools / Add-in Manager to verify that Add-in is correctly installed and configured. If you can't see it, you must reinstall the EP Development Tools.


Monday, 25 June 2012

Sequence of Form's Methods in Dynamics AX

This gives the information of method calls in the form level while
1. Opening the Form.
2. Creating/Updating/Deleting the record in the Form.
3. Closing the Form.
Sequence of Methods calls while opening the Form
Form — init ()
Form — Datasource — init ()
Form — run ()
Form — Datasource — execute Query ()
Form — Datasource — active ()
Sequence of Methods calls while closing the Form
Form — canClose ()
Form — close ()
Sequence of Methods calls while creating the record in the Form
Form — Datasource — create ()
Form — Datasource — initValue ()
Table — initValue ()
Form — Datasource — active ()
Sequence of Method calls while saving the record in the Form
Form — Datasource — ValidateWrite ()
Table — ValidateWrite ()
Form — Datasource — write ()
Table — insert ()
Sequence of Method calls while deleting the record in the Form
Form — Datasource — validatedelete ()
Table — validatedelete ()
Table — delete ()
Form — Datasource — active ()
Sequence of Methods calls while modifying the fields in the Form
Table — validateField ()
Table — modifiedField ()

Tuesday, 8 November 2011

Highlight the Selected Record Row in Axapta Report

Hi,
To highlight the  row in axapta report based on specific value just add the following code in the execution section  of section group.

public void executeSection()
{
    int usecolor
    ;
    usecolor=WinApi::RGB2int(255,0,0);
    if(inventTable.itemprice>5)
    {

        this.foregroundColor(usecolor);
    }
    else
    {
        this.foregroundColor(white);
    }
    super();

}

this will highlight all the record where item greater then 5.
I hope it works .
Regards,

Friday, 28 October 2011

How to pass parameters from Form to form

Hi,
Sometimes we want to open a form from another form with the selected record . For this we need to pass the parameters from form A to form B . This could be achieved by using args class by overriding the click method of button on form A.
In this example we will use two forms form A is salesLine form and form B is inventenquiry form. when the user will click on the button on form A it will open form B filtering the record according the form A value.lets start

  1. Put a button on form A and override its click method
  2. write the following code

void clicked()
{
    //super();
    Args args=new Args();
    Itemid itemid;
    FormRun formRun;
    ;
    args.name(formstr(InventEnquiry)); // invent enquiry is the form B
    args.parm(salesLine.ItemId);// passing the item id from Form A
 
    formRun = classFactory.formRunClass(args); /// passing the args class
    formRun.init();
    formRun.run();
    formRun.wait();
 
}
3.Now override the init method of the form B data source inventTable

public void init()
{
     super();
     if(element.args().parm())
    {

       this.query().dataSourceName('InventTable').addRange(fieldnum(InventTable,ItemId)).value(element.args().parm());
       this.query().userUpdate(false);
            this.query().interactive(false);

    }

}

Hope it helps
cheers,

Friday, 14 October 2011

How to save the report in PDF format on selected location

Hi, 
To run and save the axapta report in PDF format on your hard drive just override the init() method of your report with the following code.


public void init()
{
super();
element.printJobSettings.setTarget(PrintMedium::File); // print format is on file
element.printJobSettings.preferredTarget(PrintMedium::File);
element.printJobSettings.format(PrintFormat::PDF);
element.printJobSettings.preferredFileFormat(PrintFormat::PDF);  //file extension is pdf
element.printJobSettings.fileName("c:\\temp\\test-invoice.pdf"); // file location and name
element.printJobSettings().warnIfFileExists(false);  // dont show the option to overwrite report file
element.printJobSettings().allPages(false); // dont print all pages of report
element.printJobSettings().from(2); // print from page 2
element.printJobSettings().to(5); //print to page 5
element.query().interactive(false); // disable all dialogue 
element.report().interactive(false);
}


Regards,

Wednesday, 12 October 2011

How to pass parameters from Form to Class

Hi, 
To pass the parameters from form to class is straightforward.
1.Create a class yourClass
class yourClass { }
2. override the new method

void new(PurchID purchid)
{
;
info(Itemid);
}
---------- Class Completed
Go to form purchTable
1. Add a button
2. override the click method of the button with following code
void clicked() 
{  
PurchID purchId;
Args args=new Args();
YourClass yourClass;  
;
purchId=args.parm(purchTable.purchid);  
yourClass=new YourClass(purchid); 
}
Save and Compile
now when u will hit the button on purchTable form it will return the current purchid of the data source . I hope it will help
Cheers,



Monday, 12 September 2011

How to insert a Page footer on the last page in Axapta report

Hi, 
Normally developers need the term and condition or other stuff to be displayed only on the last page .To insert the footer only on the last page of Axapta report do the following stes.
1. Declare a boolean variable (pageFooter) in report class declaration method .

             public class ReportRun extends ObjectRun
            {
                 boolean pageFooter;
            }
2. Override the report fetch method with query 
          public boolean fetch()
          {
               boolean ret;
               ret = super();
               printPageFooter=false;
                while(queryrun.next())
                {


                }
               printPageFooter=true;
               return true;
          }


3. Override the executeSection method of footer 
      
          public void executeSection()
          {
                if(printPageFooter==true)


                super();
           }


and your done now when ever your will run a report only the last page will display the page footer. 
Regards,

Sunday, 26 June 2011

how to write select statement with while Loop in X++

Using select statement with while loop is something which has to do on daily bases to get the multiple records from statement. To exercise this statement lets assume we have a Books table which contain more then one record which we want to see. Lets write a job in editor

Static Void getBooksRecord(Args args)
{
   BookTable    bookTable;
   int records;
   ;
   while select bookTable
   {
      info("--------------NEW RECORD--------------");
      info (strfmt("BookId: %1", bookTable.BookId));
      info (strfmt("Title: %1", bookTable.BookTitle));
      info (strfmt("Author: %1", bookTable.Author));
      info (strfmt("ISBN: %1", bookTable.ISBN));
      records++;
   }
      info("------------------END-------------------");
      info(strfmt("%1 records was selected", records));
}

// Executing this Job will result in the writing  output to the Infolog. Note that only
the first records are shown in the Infolog window. When executing it yourself, you
can scroll down to see the other records at the end line