To recall a workflow through code you can use the cancelworkflow method in workflow class. It takes the correlationId and a comment as parameters and gets the job done for you. Example
workflow::cancelworkflow(CorrelationId, “Cancelling this workflow”)
Now you are probably thinking How do I find my workflows CorrelationId. You can do that by querying WorkflowTrackingStatusTable sorting it with time and instance number and joining it with SysWorkflowtable against the correlationId field and in the contextId you pass the RecId of your record for example PO RecId.
When editing a PO line for procurement category you receive Field ‘Company’ and ‘Lot ID’ must be filled in” error. This usually happens when you have brought in the PO line through some form of integration either AIF, excel plugin etc.
This error has also been seen on salesLine and there is a hotfix(KB 2756645) for when it happens on salesline.
There is no record in PurchLineForeignTradeCategory table related to PO line added.
Create a record against the PO line causing this error in the PurchLineFroeignTradeCategory table in your integration and you will see the error disappear.
In X++ we have the below methods for fetching data after any changes are made, below is the short description of what they are and when to use each one.
Refresh() refreshes the user view with whats stored in the caches. This does not touch the DB.
Use this after any form change has been made through code.
ReRead() fetches only the current record from database and does not re read the complete datasource.
Use this when you need to update only the current record after modifying any value.
ReSearch() will execute the same query again and fetch the results from the database.
Use this if you need to get the current most data from database.
ExecuteQuery() will run the query again just like research does but it will also take any query changes into account.
Use this is you have modified the query on run-time and need the updated results according to the new query.
To connect to an external database with X++ you can use Open Database Connection (ODBC) protocol through the OdbcConnection class among other ways. This approaches requires you to setup us a Data Source Name(DSN) on your server machine with the required access. Below is the code sample for how you can achieve this.To read more about this visit MSDN.
// X++, Main method in a class.
static public void Main(Args _args)
str sql, criteria;
// Set the information on the ODBC.
loginProperty = new LoginProperty();
//Create a connection to external database.
odbcConnection = new OdbcConnection(loginProperty);
sql = "SELECT * FROM MYTABLE WHERE FIELD = "
+ " ORDER BY FIELD1, FIELD2 ASC ;";
//Assert permission for executing the sql string.
perm = new SqlStatementExecutePermission(sql);
//Prepare the sql statement.
statement = odbcConnection.createStatement();
resultSet = statement.executeQuery(sql);
//Cause the sql statement to run,
//then loop through each row in the result.
//It is not possible to get field 3 and then 1.
//Always get fields in numerical order, such as 1 then 2 the 3 etc.
//Close the connection.
error("Failed to log on to the database through ODBC.");
While creating a certificate with the MakeCert utility you might face this Error: Save encoded certificate to store failed => 0x5 (5) as I did, dont be worried its not about your command the solution to this is to simply start your command prompt or powershell as an administrator and then run the command; the certificate will be created successfully.
Us ISVs( Independent Software Vendors) want to make our own customized Ax solutions to run on predefined licenses so we can better monetize our solutions, well thanks to Microsoft we now have an ISV licensing feature to do this and do not need to create our own licensing mechanisms. The ISV licensing feature includes the following key capabilities:
ISVs can generate their own Boolean licenses.
A run-time check that ensures an ISV-generated license key exists.
You can read more about ISV licensing here. In this post I will be showing you step by step how you can create your own ISV licence against a model. Before you can create a license you also need to have certificates in order to sign that license so here are the complete steps from start to end:
First and foremost make sure you implement the desired roles and security in your code and tie all objects in your solution to it.
Create a configuration key (or a parent-child configuration key hierarchy) for the solution.
All code elements must bind to a proper configuration key or a hierarchy of configuration keys.
Make sure all code written for this solution has been moved to ISV layer and to a particular model.
Create a license code in the AOT.
Set the Authenticode (x.509 Certificate) to the license file. Go to the license code properties and find the ‘CertificateName’ item and provide ‘cer’ file (the public part of the certificate, You will use the SPC.cer file for this). Keep the private key (.pfx) part secure as it will be used to generate license file. Here are some details on how to do this:
Locate windows SDK on your machine, usually comes with .Net Framework, in my case I found it at following location
Copy following files from above folder to a new folder D:\Certificate folder, this would avoid wasting your time trying to run command on C:\ with no rights
To create a test certificate you can use the makecert utility, this will give you the .cer and .pvk file; as some of you faced problems with certificates I would like to add something here that I previously missed to mention. To use our own certificate we first need to create a CA(Certificate Authority) and then publish a code signing certificate through that authority. Creating a certificate authority is done through makecert as follows on power shell run the following command to create a CA:
Assign the license code to the configuration key. In the parent configuration key, select the license code in the properties. This locks everything together if hierarchy is maintained among other configuration keys.
Generate a FULL CIL.
Export the model by going to Start > Administrative Tools > Microsoft Dynamics AX 2012 Management Shell. Enter following command: axutil export /model:[ModelName] /file:[modelfilename] /key:[keyfilename]
[ModelName] is the name of the model
[modelfilename] is the path with filename to export the model to.
[keyfilename] is the strong name key generated using SN.EXE tool, in the case you want to sign the model with a strong named key. You can skip this part if you apply next step, which is to sign the model using a certificate.
Sign the model with certificate
You need a tool ‘SignTool’. You can get by installing Windows SDK.
Run following command:
signtool sign /f “[PFX file]” /p [PFX password] “[Path to the model file]”
Once you have implemented the code with the above approach, you can then generate a license for your solution as explained below:
/file:licensefile specifies the name of the generated license file
/certificatepath:filepath specifies the path to the certificate used to generate the license file. It is the private part of the X.509 certificate used on the licensed Code within AOT; basically the .pfx file.
/licensecode:name specifies the name of the license code used to generate the license file.
/customer:name specifies the customer name used to generate the license file. This will be provided by the Customer, it will be the Customer name on the AX license they have on their installation.
/serialnumber:number specifies the serial number used to generate the license file. This will be provided by the Customer, it will be the serial number of AX license they have on their installation.
/password:value is the value that must match the password of the certificate used to generate the license file.
/expirationdate:date specifies expiration date of the generated license. This parameter is optional.
/usercount:count specifies the number of simultaneous users for the generated license. This parameter is optional. (This is not supported anymore, so you can skip this)
After running this command you can write “type [licensefilename]” to see the content if the license file.
After you have your license you will share the model file and license file with the customer, also if you have created a self signed certificate(as we did with the makecert utility) then your customer needs to trust your Certificate Authority before they import the model and license. To do this simply run the command below on your customers environment:
certutil -addstore Root CA.cer
This adds it into the Windows certificate store.
Hope this post was helpful, for any questions feel free to leave a comment. Here are some good resources that helped me understand ISV licensing.
UPDATED: To overcome the “Certificate associated with license XXX is not a trusted certificate.” Error while importing license file the complete steps for creating our own certificate have been update, please find the updates in blue text.
Developers often ask me what the difference is between the three different menu item types shown in AOT and when should you use them as it appears that all menu items inside the three ‘folders’ I would say have the same set of properties and support the same object types. So what is the difference? The answer is that there is no difference, the difference is a conceptual one rather than a functional or a technical one.
1. Display Menu item
This folder is used to contain menu items that reference runnable objects which are primarily for presenting data to the user such as forms and dialog’s.
2. Output Menu item
An output menu item should have the soul purpose to print a result, mostly used for referencing classes.
3. Action Menu item
As the name says it, you should create a menu item under this folder if your runnable object has an action to perform, for example creating or updating data.
So choosing between these three is on the developers sole discretion and I hope now you’ll be able to make a better choice for your scenario. A basic rule of thumb is: