Showing posts with label 2012. Show all posts
Showing posts with label 2012. Show all posts

1 Dec 2015

Finding primary key in a table + AX 2012


DictTable dictTable;
DictField dictField;
;
dictTable = new SysDictTable(tableNum(CustTable));
dictField = new SysDictField(dictTable.id(), dictTable.primaryKeyField());
info(dictField.name());

2 Jan 2015

Terms and Explanation Models + ax 2012

Terms and Explanations for each term.
Term
Definition
Metadata
Information about the properties or structure of data in the Application Object Tree (AOT) that is not part of the data values. Everything in the AOT is metadata.
Application layer
A single layer of the Microsoft Dynamics AX 2012 application within a model store. Elements in higher layers override elements in lower layers.
Model
A named set of elements in a given application layer. Each layer consists of one or more models, of which one is a system-generated layer model.
Model element
A single piece of metadata. For instance, a table definition is a model element. Any one element in a layer belongs to exactly one model; that is, no element can belong to two different models nor can it belong to any model.
Model file (.axmodel)
A model that has been exported from a model store. This file is the chief vehicle of metadata deployment in Microsoft Dynamics AX 2012.
Model store file (.axmodelstore)
A complete model store that has been exported from the database. The file includes all metadata, compiled artifacts, CIL code, and security artifacts. The file is used for moving consistent metadata between environments with minimum downtime.
Model store
A collection of tables in the Microsoft Dynamics AX 2012 database that house the application metadata. The model store is analogous to the AOD file share in Microsoft Dynamics AX 2009.
Generated data
Data that is generated by Microsoft Dynamics AX during development.
Transactional data
Data that describes business transactions and the state of the business.
Configuration data
Data concerning how Microsoft Dynamics AX 2012 is configured. This data includes the following subcategories:
Environment: Computer-environment–specific data. An example of environment data is the list of servers running Microsoft SQL Server® Reporting Services that Microsoft Dynamics AX 2012 is configured to use. If this data is moved, it needs to be corrected to account for new server locations.
System: Parameter settings for the Application Object Server (AOS) such as which database to connect to, or for Enterprise Portal forms.
Application: Number sequences, invoicing profiles, or other data that relates directly to the application.
Reference data
Data that is characterized by shared read operations and infrequent changes. Examples of reference data include flight schedules and product catalogs. Windows Server® AppFabric offers the local cache feature for storing this type of data.
Master data
The critical data of a business, such as customer, product, location, employee, and asset. Master data falls generally into four groupings: people, things, places, and concepts. It also can be further categorized. For example, within people, there are customer, employee, and salesperson categories. Within things, there are product, part, store, and asset categories. Within concepts, there are categories like contract, warrantee, and licenses. Finally, within places, there are office location and geographic division categories.
Definition group
A collection of tables that defines what will be exported by using the data export feature.
Common Intermediate Language (CIL)
The Common Intermediate Language instruction set is part of the specification of the Common Language Infrastructure from Microsoft and is more widely known as .NET. An older name for CIL was Microsoft intermediate language (MSIL).

9 Jul 2014

Table Inheritance + AX 2012

In Microsoft Dynamics AX 2012, tables can inherit, or extend, from the tables that are situated above them in a hierarchy. A base table contains fields that are common to all tables that derive from it. A derived table inherits these fields, but also contains fields that are unique to its purpose. Each table contains the Support Inheritance and Extends properties, which can be used to control table inheritance.

First we need understand that when we need to apply this inheritance methodology to tables. First we need to identify the Parent table and its siblings like
DataModel
Here ‘Basic Info’ is the Parent table containing fields that are required for its child table i.e. CompnayTable and EmpTable. And these tables have their own fields as well.Now to design a Inheritance pattern we need to consider following important things:

  • We can only apply inheritance on regular tables not on Temp or Memory tables
  • A type discriminator field must be defined on any table inheritance hierarchy created in the AOT. The field must be defined as an int64 type on the root table, with the name of the field set to InstanceRelationType.
  • The InstanceRelationType field of the root table is read-only and stores the TableIDs of record instances; it is populated automatically by Microsoft Dynamics AX 2012.
  • Also we can only set the table properties for the table inheritance only when there are no fields in the table.
  • If these requirements are not met, a compilation error will occur when the table inheritance hierarchy is compiled.
Let create parent Table ‘BasicInfo’
BasicInfo
Setting its SuppourtInheritance Prpoerty to Yes
SupportInhheritane
When you save and compile,it will give following error
ComipleError
For this we need to create a discriminator; name ‘InstanceRelationType’ and of type Int64.Now I have created a field including discriminator
InstanceRelationTYpe
Finally I have set another table property ‘InstanceRelationType’ to ‘InstanceRelationType’  field
InstanceRelationTYpeProperty.jpg
And when I compiled, the error is gone now.
Now we have to create Two child tables
EmpTable:
First I have set the ‘SupportInheritance Property to Yes.
SupportInheritance
Now for the child table to have the parent we need to set the ‘Extends’ property of child table to parent table value like
ExtendsProperty
And finally added all fields.
EmpTable

CompanyTable:
Same as what already we have done for EmpTable
Now when I compile it still give the two errors i.e.
TwoCompilerErrors
Basically these errors indicates that the automatic relation that have been created in the child table,have the same relation name and so it is showing duplicate so for this I have changed the name See below screen shot
ScreenShot (see below)
 FinalScreenShot
And that’s it we have created Parent-child hierarchy table .
Finally, we need to also set the ‘Abstract’ property of the parent table to ‘Yes’ and for this we need to understand below.
Abstract versus concrete tables:
Tables in a table inheritance hierarchy can be defined as either abstract or concrete, depending on whether the table property Abstract is set to Yes or No. Records can only be created for concrete table types. Any attempt to create a record and insert it in an abstract table will result in a run-time error. The position of the table in the inheritance hierarchy does not restrict its ability to be defined as abstract.

11 Apr 2014

Override permissions in a Role

I recently came across a trick on setting up security in AX 2012. We wanted to create a new role by copying an existing role and removing a few duties from the role. I managed copying the role through some coding and that went well. However, when I tested the new role, it doesn't behave exactly the same as the original role. After poking around a bit, I found this nice new function in AX 2012 "Override Permissions" on the role form. As Microsoft noted, "Overrides for securable objects are not associated with specific duties or privileges. If you apply an override, the access level for the object is set for the role, regardless of access levels specified by the duties and privileges assigned to that role." I found this is better and easier than changing the duties or privilege itself.





You can also go to the AOT and look up in the table SecurityRolePermissionOverride and see what permissions are overridden.



One last note, you don't want to override too many permissions as it'll slow down your system performance.


New things on AX 2012 security settings.

Unlike AX 2009, any change from the Security Role/Privileges form (e.g. adding a new role, adding/removing a duty from a role) auto triggers a change on the AOT under the Security section! If you're working from a usr layer (as a regular functional consultant would do), the changes will be on the USR layer!! I learned this in a hard way as I found all my security settings gone after a recent code deployment. So, if you don't want to keep redo your security settings in AX 2012, log onto the CUS layer and do the configuration, or merge the code after you're done on the USR layer.
Another way to duplicate an existing role is to go to AOT>Security>Roles and duplicate the role. Then all duties and permissions will get copied to the new role. Much better.


5 Dec 2013

Startup message + ax 2012

  1. Open the Configuration Utility (Start > Control Panel > Administrative Tools > Microsoft Dynamics AX Configuration Utility).
  2. Verify that the currently open configuration target and configuration are the ones you want to modify.
  3. On the General tab, in the Startup message box, enter the message you want to display, and then click OK.
    When the client is started, the text displays in a message box, with an OK button below.

2 Dec 2013

Workflow History Form in AX 2012?

If you’ve stated to use workflow in AX2012 you’ve probably noticed that the workflow history from is no longer where it used to be. Previously in AX2009 it was available under Basic -> Enquires -> Workflow History.



You can now find the workflow History Form in AX 2012 under Home -> Enquiries -> Workflow -> Workflow History.

28 Nov 2013

WINAPI functions and their use

Like most AX developers I use the WINAPI class quite often. Its a very useful class when handling files that need to be accessed outside of the AX environment


  static void FO_WinApi(Args _args)
  {
      str     root        = "C:";
      str     path        = "C:\\dionne";
      str     fileName    = "SalesInvoice.pdf";
      str     fileName2   = "SalesInvoice1.pdf";
      str     file        = path + "\\" + fileName;
      str     file2       = path + "\\" + fileName2;
      int     x, y;
      ;

      // Does folder exist?
      print WinAPI::folderExists(path);

      // Does file exist?
      print WinAPI::fileExists(file);

      // Copy file.
      print WinAPI::copyFile(file,file2);

      // New file exists?
      print WinAPI::fileExists(file2);

      // Delete new file.
      print WinAPI::deleteFile(file2);

      // New file still there?
      print WinAPI::fileExists(file2);

      // Get current cursor position.
      [x, y] = WinAPI::getCursorPos();

      print x;
      print y;

      // Get time and date format.
      print WinAPI::getSystemLocaleDateStr();
      print WinAPI::getSystemLocaleTimeStr();

      // Gets current computer name.
      print WinAPI::getComputerName();

      // Gets total disk space.
      print int2str(WinAPI::getDiskTotalSpaceInKb(root)
             / 1000) + " MB";

      // Gets current free space on disk.
      print int2str(WinAPI::getDiskFreeSpaceInKb(root)
             / 1000) + " MB";

      // Date when file was last accessed.
      print WinAPI::getFileAccessedDate(file);

      // Time when file was last accessed(In seconds).
      print WinAPI::getFileAccessedTime(file);

      // Gets path to temp directory.
      print WinAPI::getTempPath();

      // Gets a generated temporary filename, prefix "FO_".
      print WinAPI::getTempFilename(path, "FO_");

      pause;

  }
In addition to file information the WINAPI class can execute different file types from within Dynamics AX by of course using the file name as a parameter.
For example lets say you want to launch a PDF file saved in table within AX. WinAPI::ShellExecute() will do this for you.

26 Nov 2013

Query Range Extending in Dynamics AX

Developers often stuck while they try to apply range to the dynamics ax query to filter records based on some conditions. We will try to explore the query ranges in this article and will try to play with some examples to learn how we can apply query ranges using x++ to the Dynamics AX queries.
Lets discussed different cases...


Query q;
QueryBuildDataSource qbd;
QueryBuildRange qbr;
q = new Query();
qbd = q.addDataSource(TableNum(CustTable));
qbr = qbd.addRange(FieldNum(CustTable, AccountNum));
qbr.value('4005, 4006');


The above x++ code will generate following SQL statement.

"SELECT * FROM CustTable WHERE ((AccountNum = N'4005' OR AccountNum = N'4006'))"

qbr.value(strFmt('((AccountNum == "%1")
(AccountNum == "%2"))',
QueryValue('4005'),
QueryValue('4006')));

The above x++ code will generate following SQL statement.

"SELECT * FROM CustTable WHERE ((((AccountNum == "4005") || (AccountNum == "4006"))))"

Let's say we want to apply "OR" range on a DIFFERENT fields
You can use the following x++ code to apply the OR range to the different fields


qbr = qbd.addRange(FieldNum(CustTable, DataAreaId));
qbr.value(strFmt('((%1 == "4000")
(%2 == "The Bulb"))',
fieldStr(CustTable, AccountNum),
fieldStr(CustTable, Name)));

The above code will generate following sql statement

"SELECT * FROM CustTable WHERE ((((AccountNum == "4000") || (Name == "The Axapta"))))"

Note: We have used DataAreaId field above to apply the range however, the actual range is on AccountName and AccountNum field. This means when you use range value expressions you can use any field to obtain range object and use it to insert your range in the query. Using DataAreaId field for this purpose is the best practice.

25 Nov 2013

an unbalanced x++ TTSBEGIN/TTSCOMMIT pair has been detected.causes of this include(a) too many + Ax 2012

Error: 
clip_image001 


Reason(s): 

TTS level '1' usually leaves your Ax session in an unusable state 
that you can't close properly. 
Check all code for form or class from where this error comes and count the ttsbegin and ttscommit there must be same like if u write 2 ttsbegin u must have to write 2 ttscommit. 

Solution: 

To resolve this error this TTS level should be ZERO, Run this job to get rid of that error, this job will find the tts level where its greater than zero and make it zero by calling TTSABORT. 

static void resetTTS(Args _args)
{
while (appl.ttsLevel() > 0)
ttsAbort;
}


Note::

ttsBegin: marks the beginning of a transaction. This ensures data integrity, and guarantees that all updates performed until the transaction ends (by ttsCommit or ttsAbort) are consistent (all or none). 
ttsCommit: marks the successful end of a transaction. This ends and commits a transaction. MorphX guarantees that a committed transaction will be performed according to intentions. 

13 Nov 2013

Vertical splitters on Forms + AX 2012

Vertical splitter is the separator that is aligned vertically on the Ax Form and it separates two section on the Form. Use can also stretch or expand the section by dragging this splitter. You can find the snap shot below



What are steps to achieve this functionality?

1. Make a group sections as follows and make a separate group for vertical splitter as below .



2. Set the style property of the Group container to as follows. Make the AutoDeclaration to Yes also.



3. Go to the Form class declaration and declare the variable that will hold the object of vertical splitter

SysFormSplitter_X VerticalSplitter;

4. Go to the Form init method and initialize the object as below

VerticalSplitter = new SysFormSplitter_X(VSplitter, Container, element);

5. hopeeeeeeeee, you vertical splitter is ready

If you want example checkout  "MAINACCOUNT" Form.

I hope this will helpful somebody.....

8 Nov 2013

Alerts + AX 2012

Dynamics Ax2012 facilitates the Alerts mechanism out of the box which can be used commonly across the modules for new implementations. Especially to fulfill the users wish on getting alerts and helping them in their daily activities.

Let us take few business scenarios as example to know how it plays a big role in alerting the user.
Susan from procurement team handles the RFQ (Request for quotation) process in the organization. He processes 100 RFQs each day. To track the Expiry date of the RFQ and compare the quotations received from different suppliers on completion of “Expiry date” is a tedious work for him. He wants to be alerted a day before the expiry date of the RFQ. How can we help him?
Rajat is an accounting manager and who is not involved in PR approvals but still he wants to be alerted or notified whenever a purchase requisition is approved.
Sunny is inventory manager and wants to be alerted whenever Inventory clerk creates an item in the Item master.

Dynamics AX2012 alerting mechanism can be used to address all these scenarios. AX2012 has two kinds of alerts which can be be used accordingly to achieve the same.
  • Change based alerts
  • Due date alerts
Change based alerts: With respect to a particular field we can setup the alert rule to alert the specific user. As per our scenario,  I am going to create an alert rule to alert someone when the PR is approved.
Go to PR header>focus on the status field in the header> right click >Create alert rule, which opens the below form. It has below 4 alerting options



  • Has changed – Alerts whenever the value in this field has changed
  • Is set to – Alerts whenever the field is set to a particular value
  • Create and deleted: whenever a record has been created or alerted
We can use “Is set to” option here to alert whenever PR “status” is set to – Approved. In the “Alert who” node specify the user who should be alerted.

Due date alerts:
Similarly, for the due date alerts, select the date field you want to get the alerts for >Right click>Create alert rule



Choose the event “due in” and specify the days i.e., how many days before you want to alert the user. Jump on the other events that you are seeing to know how you can make the best use of it.
Similarly, using the event “Record has been created” will alert the user when a record is been created in that table.

Sticky notes: How can we alert multiple users for the event? Create another alert rule and specify the different user id .
What if a user wants to be alerted only when the POs from particular vendor are invoiced? Just use the select button to specify the condition to meet to get the alert. (Apply this querying based on the client requirements).

Considerations:
Just creating the alert rule is not enough to get the alert. You will also need to work on initiating the batch processing to get the alerts triggered.

Go to system administration>setup>Alerts> Change based alerts and Due date based alerts to route it through batch processing.


In the form, select the batch processing check box and click recurrence to define recurrence interval for the alerts triggering.

After doing this, go to system administration>inquiries> Batch jobs to ensure whether the batch job created. (You will get to see the alerts only if the job is added to this batch jobs form)


Last but not least, set up the user options for the users who want to be alerted.
Go to system administration>Users>Select each user>go to options and click the “notifications” tab.


Set the value in minute’s field to see the pop up for every x minutes. Now, everything is done and we should receive the alerts.



AX home and all the forms will have the alerts symbol, clicking on which will show you the notifications.
Setting “Send alert as e-mail message” option sends the notifications as e-mail.

31 Oct 2013

Maps AX 2012

Maps are nothing just an element/object the makes possible to link/associate map fields with fields(same type with different names) in different tables like, I have create a MAP with field (AccountNum) and Same field exist in CustTable and also in VendTable,so I can associate field in CustTable and in VendTable with Maps, so basically  Maps enables to access the fields with different name in different tables.
EXAMPLE:
I have created a Map by navigating to AOT>Data Dictionary>Maps and right click and new and gave it name ‘MapTest’
map1
I have created 4 fields in under Fields node in Map (drag and drop from EDT)
map2
Now the next thing I need to do is to associate the fields in map with the fields in different tables, let say I am taking two tables (CustTable and VendTable).
map3
Notice that above, four fields that I have created in Maps also exist in CustTable as well as VendTable with different names.
To associate fields, go to Mapping node, right click it and click New mapping, and enter the table that you want to associate in Mapping Table field. Like
map4
And the associate fields with fields in MAP
map5
Now I have created a method called printInfo under method node in Maps, which print the value of the map field AccNumber.
public void printInfo()
{
info(strFmt(“Map : AccountNum :%1″,this.AccNumber));
}
Similiarly I have create same methods under method nodes of CustTable and VendTable which are printing their respective AccountNumber fields
map7 map8
Now finally I have created a job see below I  am not describing every line  added comments above the line.
map9
When I run this job see what happens
map10

28 Oct 2013

Security – AX 2012

The extensible data security framework is a new feature in Microsoft Dynamics AX 2012 that enables developers and administrators to secure data in shared tables such that users have access to only the part of the table that is allowed by the enforced policy. This feature can be used in conjunction with role-based security (also supported in Microsoft Dynamics AX 2012) to provide more comprehensive security than was possible in the past.

Extensible data security is an evolution of the record-level security (RLS) that was available in earlier versions of Microsoft Dynamics AX. Extensible data security policies, when deployed, are enforced, regardless of whether data is being accessed through the Microsoft Dynamics AX rich client forms, Enterprise Portal webpages, SSRS reports, or .NET Services [MS help]

simple example:

Requirement is to show a particular user only those Bank accounts that belongs to the Bank group “BankCNY”

Below are the Bank accounts that are available in my system. By using policy framework on roles , I can restrict user to view only bank accounts that belong to Bank group “BankCNY”



First of all , where are these policies in AX? They are actually in the AOT >> Security >> Policies



Before we create policies, we need to create a query to use it in policies. Remember, try to optimize the queries to the best otherwise it might lead to performance issues.

To keep it very simple, Create a Query by name SR_BankAccountTable by adding data source[PrimaryTable] as “BankAccountTable” and add a range on BankGroupId field and set it to “BankCNY” as shown below




Now let us create a new Role by name SR_BankController as shown below

Go to AOT >> Security >> Roles >> New Role



Set the following properties of the newly created role by right clicking and going to properties



Now lets create duties for this role: In this example I will create one simple duty called “SR_BankAccountsMaintain”

Go to AOT >> Security >> Duties >> Right click >> New Duty



Set the following properties for the newly create duty. Name it as “SR_BankAccountsMaintain” and provide label and description as shown below



Now, let us create a new privilege and add entry points [Menu Items] to it to provide only access to the user

Go to AOT >> Security >> Privilege >> New Privilege.



Name the privilege as “SR_BankAccountTableMaintain” and set the label and Description as shown below



Now drag and drop some menu items on to Entry points from AOT >> Menu Items >> Display as shown below



Now add this newly created privilege “SR_BankAccountTableMaintain” to the duty “SR_BankAccountMaintain” which we have created.



Then, add SR_BankAccountsMaintain duty to the Role SR_BankController



Now, let us create a new Policy by name “SR_BankAccountPolicy” and set the properties as shown below



Set the below properties



In the above screen, Select the context type as “RoleName“ and the role “SR_BankController” and select the query as ”SR_BankAccountTable”

PrimaryTable : should always be the first data source Table which you have added in the query. So, select BankAccountTable

A constrained table is the table or tables in a given security policy from which data is filtered or secured, based on the associated policy query. For example, in a policy that secures all sales orders based on the customer group, the Sales Order table would be the constrained table. Constrained tables are always explicitly related to the primary table in the policy [MS Help]


A policy context is a piece of information that controls the circumstances under which a given policy is considered to be applicable. If this context is not set, then the policy, even if enabled, is not enforced.
Contexts can be of two types: role contexts, and application contexts. A role context enables policy application based on the role or roles to which the user has been assigned. An application context enables policy application based on information set by the application

we are almost done, we need to add this role= to some user and verify whether he is able to see only Bank accounts that belongs to BankCNY group

Go to System Administration >> Users >> select any user >> Click on Assign roles.

Select “Bank Accounts controller” and click on Ok Button.



Now , let us log in with the user credentials for which we have assigned the new Role and verify the Bank accounts.

As you see, the user can only see the Bank accounts which belong to “BankCNY” group.




Create number sequence in D365 FO

Create the data type. Add code in the loadModule method of the appropriate NumberSeqModule subclass. Add a method to the module’s paramet...