13 Ağustos 2010 Cuma

Using fieldid & fieldname to set value

Assume that your class gets data from various tables.

CustVendVoucher -> initCustVendTrans method
...
fieldid = fieldName2Id(common.TableId,'Payment');
if (fieldid)
{
custVendTrans.Payment = common.(fieldid); // You must create mappings
}
....

AX2009 How to get XML from site using proxy

xml TNC_getXML()
{
System.Net.HttpWebResponse httpresponse;
System.Net.WebRequest webrequest;
System.Net.WebResponse webResponse;
System.Net.HttpWebRequest httprequest;
System.Net.IWebProxy proxy;
System.Net.WebPermission webPermission;

System.IO.Stream stream;
System.IO.StreamReader streamreader;
System.Text.Encoding encoding;
xml xml;
interopPermission interopPermission;
int i;

interopPermission = new InteropPermission(InteropKind::ClrInterop);
InteropPermission.assert();
try
{

webrequest = System.Net.WebRequest::Create("../../...xml");

proxy = System.Net.WebRequest::GetSystemWebProxy();
proxy.set_Credentials(System.Net.CredentialCache::get_DefaultCredentials());
webRequest.set_Proxy(proxy);

httpresponse = webRequest.GetResponse();
stream = httpresponse.GetResponseStream();
streamreader = new System.IO.StreamReader(stream);

xml = streamreader.ReadToEnd();

codeAccessPermission::revertAssert();
}
catch
{
error("Connection Error");
}
}

Ax2009 Update object properties on AOT

static void tnc_updateTableLog(Args _args)
{
TreeNode aNode = TreeNode::findNode('\\Data Dictionary\\Tables').AOTfirstChild();
int i;
#Properties
str tproperties;
;
while (aNode)
{

tproperties = anode.AOTgetProperties();
tproperties = setproperty(tproperties, #PropertyCreatedBy,'Yes');
anode.AOTsetProperties(tproperties);
anode.AOTsave();
info(anode.AOTname());
aNode = aNode.AOTnextSibling();
i++;
// if (i>10) break;
}
}

Ax conditional values on query range

Field name can be used in the range expression :

SysQuery::findOrCreateRange(this.query().dataSourceName(identifierstr(CustTrans)),fieldnum(CustTrans,SettleAmountCur)).value('(SettleAmountCur < AmountCur)');