Tuesday 19 August 2014

Microsoft Dynamics AX 2012: How to get Company,Customer and Vendor address in AX 2012

Scenario:  “How to get Addresses of Customer, Vendor and Company

1)      First we need to identify which table store address of each entity
Table : LogisticsPostalAddress  : In Dynamics AX 2012 this is the main table which stores every address of each entity(customer/vendor…).This table contains fields like city,country,state,zipCode etc. required for the address.
a)      Customer/Vendor  address
Assume that we have the customer with CustAccount = 1103 and has the address and infact which is the primary/main address.(below)
Img1
Now if we want to get this specific customer address we can use the following code.
Img2
Simliar for the Vendor
Img3
Use following code:
Img4
a)      Company Address
For the Company address we can use the CompnayInfo table to get first the company and then find its address in LogisticsPostalAddress table.
We can find the LogisticsPostalAddress of the current company by Location .
This line give the location of the current company
Now get the logisticsPostalAddress reference we can use and find the address
So,
Img5

Img6

Wednesday 6 August 2014

SSRS Error Issues


1.          Deployment Strategy

Steps to resolve the issues related to deployment

a)       Delete deployed report in SSRS Report Manager
b)       Clear caches
c)       Clear usage data
d)       Delete record from SRSReportParameters and SRSReportQuery in AX - sql administration >> Periodic >> DataBase >> SQL administration
e)       Restart AOS
f)         Restart SSRS
g)       Check in SSRS report in AOT if checked out and then re-check out.
h)      Redeploy report from VS
i) Delete records from SyslastValue Table (System Tables),PrintMgmtReportFormat delete records related to your report
j) Delete report from SSRS report manager.
h) deploy the report in VS.

Tuesday 5 August 2014

Cross company reports [AllowCrossCompany] in Dynamics AX , X++

Cross company reports [AllowCrossCompany] in Dynamics AX , X++


This report example will help you to get the data from selected companies or all companies using AllowCrossCompany property
In the AOT, query node objects have the AllowCrossCompany property listed in the Properties window. For new queries the default value is No (which is equivalent to false in X++ code). To make a query cross-company you need to set AllowCrossCompany to Yes.
The classes QueryRun and Query both have the AllowCrossCompany property, but their values always equal each other. When you read AllowCrossCompany from QueryRun, QueryRun reads it from Query. When you set AllowCrossCompany on QueryRun, it sets in on Query.
Please follow me to get the report from multiple companies as shown below.
Right click on AOT >> Reports and Create a new report by name “SR_CrossCompanyItems” as shown below
Expand the datasources and add InventTable as datasource.
On the Query Node, right click and go to property and set the AllowCrossCompany peroperty to “Yes” as shown below.
Expand the design and add Body control to it . Add three fields [ItemId, ItemName and DataAreaId] from the InventTable datasources [Drag- Drop] as shown below
Right click on the report and open the report
Select the print medium as screen and below is the output
If you want to restrict the report to only selected companies data , override the report init() method and add the following code in the init() method
public void init()
{
super();
this.query().allowCrossCompany(true);
this.query().addCompanyRange(“dat”);
this.query().addCompanyRange(“ceu”);
}

Adding a role to all or multiple users using X++ Code [Dynamics AX 2012]


In AX 2012, we can add a role to all the users by running the automated role assignment job based on the rule which we define in the “Assign users to Role” form.
Navigation : System administration >> Setup >> Security >> Assign users to rolesassign users
And the code behind this is :
SysSecurityDynamicRoleAssignment::synchronize(args.record().RecId); // selected Role (this is Security Role table buffer) in the form
I tried to run the above code independently by passing the “Budget clerk” Security Role but did not work due to obvious reasons as it needed a rule assignment table buffer.
The equivalent code to assign a role to all users is below.
This doesn’t need to add any rules like what we do in the form.This is just an experiment to handle the roles through code and request to test the code before using it.
static void SR_AssignRoleToAllUsers(Args _args)
{
    SecurityRole        role;
    SecurityUserRole    userRole;
    boolean             added;
    UserInfo            userInfo;
    ;

    select role where role.Name == ‘Budget clerk’;
    while select userInfo
    {
        select * from userRole
            where userRole.SecurityRole == role.RecId &&
                userRole.User == userInfo.id;

        if (!userRole || (userRole.AssignmentStatus != RoleAssignmentStatus::Enabled))
        {
            info(strFmt(‘Role %1 added to the user %2 successfully.’, role.Name, userInfo.id));

            userRole.User = userInfo.id;
            userRole.SecurityRole = role.RecId;
            userRole.AssignmentMode = RoleAssignmentMode::Manual;
            userRole.AssignmentStatus = RoleAssignmentStatus::Enabled;
            SecuritySegregationOfDuties::assignUserToRole(userRole, null);
        }
        else
        {
            warning(strFmt(‘skipping – Role %1 to the user %2.’, role.Name, userInfo.id));
        }
    }
}