To start the Table Browser on system tables, e.g., UserInfo or UserGroupList, go to:
AOT > System Documentation > Tables > [Table name] - right-click Add-Ins > Table browser
To obtain the name of the computer on which this code executes:
info(WinAPI::getComputerName());
To pass a container to an object in Args you need to encapsulate the container in an object, e.g.:
Container c = [1,2,3]; ContainerClass cc = new ContainerClass(c); ; _args = new Args(); _args.parmObject(cc); theClassToCall::main(_args);And in the receiving class:
static void main(Args _args) { ContainerClass cc; Container c; ; cc = _args.parmObject(); c = cc.value(); }
AxCreateNewProject: a project that makes it easyer to create new projects in Dynamics AX.
To determine whether code is running on server or client, use:
info(global::isRunningOnServer() ? "on server" : "on client");
To open a browser on a web page from Dynamics AX, use:
infolog.urlLookup("http://lehr.dk");
or
winApi::shellExecute("http://lehr.dk");
To get the server name of the current AOS server, use (returns an empty string in 2-tier (Dynamics AX 3.0)):
xSession xSession = new xSession();
;
info(xSession.AOSName());
How to use insert_recordset
to insert
from several tables:
insert_recordset T1 (A, B)
select A from T2
where T2....
join B from T3
where T3...
Splitting filenames (very handy):
[path, filenameOnly, type] = fileNameSplit(filename);
Getting a label in another than the current language:
SysLabel::labelId2String(literalstr("@SYS1"), 'en-gb')
Setting properties on fields on a datasource
Example 1:DB_VendWorkfloweInvoice_DS.object(FieldId2Ext(FieldNum(DB_VendWorkfloweInvoice,Dimension),2)).visible(false);
Example 2:DB_VendWorkflowPosting_DS.object(FieldNum(DB_VendWorkflowPosting,AccountNum)).allowEdit(false);
Base64 decoding a string in Dynamics AX 3.0
I've developed this method to do it:
// Transforms the base64 encoded string _encoded to it's binary representation.
// Throws an error on errors.
static Binary base64decode(str _encoded)
{
// The size in bytes of the binary representation is found by trying
// to convert until it fits
#define.minTIFSz(30000) // Minimum try
#define.maxTIFSz(900000) // Maximum try
#define.TIFSzInc(10000) // Increments during trying
#define.sizeOfInt(4)
#define.moredata(234)
DLL DLL = new DLL('crypt32.dll');
DLLFunction decode = new DLLFunction(DLL, 'CryptStringToBinaryA');
int retval; // BOOL
int encodedlen;
int lasterr;
Binary decoded;
Binary junk1 = new Binary(#SizeOfInt);
Binary junk2 = new Binary(#SizeOfInt);
Binary size = new Binary(#SizeOfInt);
int TIFsz;
/*
http://msdn.microsoft.com/en-us/library/aa380285(VS.85).aspx
BOOL WINAPI CryptStringToBinary(
__in LPCTSTR pszString,
__in DWORD cchString,
__in DWORD dwFlags,
__in BYTE *pbBinary,
__inout DWORD *pcbBinary,
__out DWORD *pdwSkip,
__out DWORD *pdwFlags
);
*/
decode.returns(ExtTypes::DWord); // BOOL
decode.arg(
Exttypes::String, // __in LPCTSTR pszString,
Exttypes::DWord, // __in DWORD cchString,
Exttypes::DWord, // __in DWORD dwFlags,
Exttypes::Pointer, // __in BYTE *pbBinary,
Exttypes::Pointer, // __inout DWORD *pcbBinary,
Exttypes::Pointer, // __out DWORD *pdwSkip,
Exttypes::Pointer // __out DWORD *pdwFlags
);
encodedlen = strlen(_encoded);
TIFSz = #minTIFSz;
lasterr = #moredata;
while (lasterr == #moredata) // As long as the image is too large
{
if (TIFSz > #maxTIFSz)
throw error(strfmt("The eInvoice image is larger than %1 bytes - cannot handle this",#maxTIFSz)); //TODO:Label
decoded = new Binary(TIFSz);
Size.dWord(0,TIFSz);
retval = decode.call(
_encoded,
encodedlen,
1, // Base64, without headers
decoded,
size,
junk1,
junk2);
lasterr = DLL::lastDLLError();
TifSz += #TIFSzInc;
}
if (!retval)
{
throw error(strfmt("%1 (%2)",WINAPI::formatMessage(lasterr),lasterr));
}
return decoded;
}