Powered By Blogger

Wednesday, April 13, 2011

User 'UserName' is not authorized to insert a record in table 'TableName'. Request denied. Cannot create a record in TableLabel (TableName).

DAX folks,

This was really weird for me while dealing with this issue arises during posting the invoice journal(project>inquiries>Invoice>invoice Journal).

User which was trying to post this had several user groups and among them few of them have "NO ACCESS" to the table 'projInvoiceJour' which i never even thought will make any difference b4 encountering this horrible episode.

After doing some research and analysis it was revealed that AOSAuthorization property on the table is the culprit -:). For handling this there is a line of code which needs to be used where records are getting inserted into this table.

unchecked(Uncheck::TableSecurityPermission)
{
projInvoiceJour.insert();
}


Even easiest thing to handle this is just change the AOSAuthorization property on the specific table but STOP! Don't do that as it will put your data at high risk. So better opt for above script.

Hope you doesn't fight too much and script help.

Monday, April 11, 2011

DAX2009: DateTimeUtil::anyToDateTime()

While working in AX2009, i have been Juggling with anyToDateTime() method of DateTimeUtil class. If you use the below code above error will get encountered on the fly.

UtcDateTime dt;
Date d = 01\03\2009;
;
dt = DateTimeUtil::anyToDateTime(d);
info(strFmt('%1', dt));


In order to get this fixed we have to pass any time by using below method of dateTimeUtil class.

dt = DateTimeUtil::newDateTime(d,str2time('00:00:00'));








Thursday, April 7, 2011

Multiple table properties update

Guys -

Sometimes if you need to update a set of tables (sales*,proj*,purch*,address*) for few properties. You can opt
below script which basically look in all that related tables that are in the database (SQLDictionary) and keep on iterating until all that tables gets updated.



static void ChangeTableProperties(Args _args)
{
SQLDictionary dictionary;
TreeNode treeNode;
str properties;
Counter i;
;
while select dictionary
where dictionary.fieldId == 0 && dictionary.name like("Address*")
{
treeNode = TreeNode::findNode('\\data dictionary\\tables\\' + dictionary.name);
if (treeNode)
{
properties = treeNode.AOTgetProperties();
properties = setProperty(properties, 'CreatedDateTime', 'Yes');
properties = setProperty(properties, 'CreatedBy', 'Yes');
treeNode.AOTsetProperties(properties);
treeNode.AOTsave();
i++;
}
}
info(strfmt("NO of tables which has been updated - %1",i));
}

Where is the code running?

DAX folks,

Sometimes its gets very irritating to identify where is this code running actually, server or client.

Just try adding below info line after the code, it must tell you where the code execution happens.

info(strfmt("%1",xGlobal::clientKind()));

Thursday, March 17, 2011

Custom Lookup - 'group by' doesnt work

ALL,

During on of my project task i was trying for 'group by' on a lookup but strange it works for the first shot when i expanded the lookup and selected any value.
But unfortunately when i tried changing the lookup to some other value again all the values shown up in the lookup and grouping was no more active.

I was really puzzled with all options i was aware of but after further on the 'sysTableLookup' methods, found one method which helps finally.

sysTableLookup.parmUseLookupValue(false); - this should be passed as FALSE.

Hope it helps some of you.


Thanks,

Friday, July 2, 2010

Exporting table data to a xml doc in Ax using X++

Main thing which is associated with XML in Dynamics AX is the AIF that allows exposing business logic or exchanging data with other external systems. The communication is done by using XML formatted documents. By using existing XML framework application classes prefixed with Axd, you can export or import data from or to the system in an XML format. It is also possible to create new Axd classes using the AIF Document Service Wizard from the Tools Wizards menu to support exporting and importing newly created tables.

Apart from this AX also contains a set of application classes prefixed with Xml like XmlDocument, XmlNode etc to handle the xml import/export which are basically wrappers around the System.

This recipe to show the principle of XML, we will create a new simple XML document by
using the standard xml classes. We will create the file with the data from the chart of accounts table and will save it as an XML file.

just copy the below code and put in a new class named as 'CreateXmlFile' and run it....it will create the xml file at C:\ with the name of 'test'...


public static void main(Args _args)
{
XmlDocument doc;
XmlElement nodeAccount, nodeName, nodeTable, nodeXml;
LedgerTable ledgerTable;
#define.filename("C:\\Test.xml")

;

// Creating a new XmlDocument, which represents an XML structure using its newBlank() method.

doc = XmlDocument::newBlank();

// create it's root node named xml using createElement(), and add the node to the document by calling appendChild().
nodeXml = doc.createElement('xml');
doc.appendChild(nodeXml);

// Query on the table and use the fields which we wanted to include in the xml file.

while select ledgerTable
{
nodeTable = doc.createElement(tablestr(ledgerTable));

nodeTable.setAttribute(fieldstr(LedgerTable, RecId), int642str(ledgerTable.RecId));
nodeXml.appendChild(nodeTable);

nodeAccount = doc.createElement(fieldstr(LedgerTable, AccountNum));
nodeAccount.appendChild(doc.createTextNode(ledgerTable.AccountNum));
nodeTable.appendChild(nodeAccount);

nodeName = doc.createElement(fieldstr(LedgerTable, AccountName));
nodeName.appendChild(doc.createTextNode(ledgerTable.AccountName));
nodeTable.appendChild(nodeName);
}

doc.save(#filename);
}

Thursday, June 24, 2010

How to open a form in workspace in DAX2009 like in AX 4.0

ALL,

You all might be aware that all forms in Ax2009 are behaving like an independent application forms and used to open in a separate window which becomes a bit cumbersome 2 handle.

While doing some work over it, i found something not to go with this and restrict DAX to open the forms in workspace rather in a separate window as a workaround (though it's an intentional design in product).

There are two ways to handle it..
1. Just put the below code to the 'SysSetupFormRun' class b4 super() call.

this.form().design().windowType(FormWindowType::Workspace);
super();

2. Change the formdesign property windowtype from standard to workspace. This has to be done for all the forms user wanted 'not 2 open' in a separate window.

Enjoy same feel 2 work in DAx2009.

Cheers DaXing.......