Skip to main content

Posts

Indicating mandatory field in a dialog (RunBase) class.

A classical problem is indicating that a field is mandatory in a dialog, when the field is not bound to a datasource/field in a datasource. Normally fellow developers will tell you that, that is not possible. I found a way to do this. In your Runbase-based class you can implement the putToDialog-method e.g like this: protected void putToDialog() { super(); fieldMask.fieldControl().mandatory(true); } where fieldMask is a DialogField object in your dialog. This will make the field act like it was a mandatory field from a datasource in a form, showing a red-wavy line under the field, and requiring the field to have a value. Attention: Your class has to run on the client.If you set your class to run on the server, you get a run-time error, when the fieldMask.FieldControl()-call is made.

Getting the active company accounts programmatically

While working on a client case where custom made data export was needed, I coded some classes to make the export. While working with the code, I decided it would be a good idea to make the currently chosen company id a part of the file name when exporting, as the customer have several company accounts, and we need to export from all of them. I spent a little time to find out how to get the current selected company account id and I came up with: static void Job77(Args _args) { ; info(appl.company().ext()); } So I made a function for constructing the file name and put the appl.company().ext() bit in that.

How to programmatically (X++) calculate a mathematical expression i Dynamics AX

This code snippet shows how to calculate a mathematical expression and get the result in X++ code (the shown code is made as a job): static void calc(Args _args) { XppCompiler x; // In str s we write the expression that we want to evaluate Str s = "1+2*(8+4)*cos(25)"; Str result; ; x = new XppCompiler(); if (x.compileExpr(s)) { result = x.execute(); } else { result = "Error in formula"; } info(result); }