MIIS/ILM/FIM Code Experiment: Dynamics AX Management Agent (part 3)
One of the things I was tasked with was to set the initial Dynamics AX password for a new user. I used information derived from our HR source to create the first password. This information needed to be encrypted in Dynamics AX on export, so the password encryption piece was added into the AX management agent. We'll actually call an internal Dynamics X++ method to perform the encryption.
I mentioned a global variable in the previous post
Axapta ax = new Axapta();
This is an Axapta class object from the Microsoft.Dynamics.BusinessConnectorNet namespace.
In the ExportEntry() method, we loop through the different tables in Dynamics and populate attributes, but first we need to create an AxaptaRecord class object against a table in Dynamics AX. In this example, "table" is a string "RBOSTAFFTABLE."
AxaptaRecord axRec; axRec.CreateAxaptaRecord(table);
Since we're solely creating new users, we loop through the attributes and use the set_Field property to populate the AX table with the Connector Space entry attributes. I am not going to bore you with those details. However, Dynamics AX requires that the password attribute be encrypted. Since we don't have access to the encryption method for export attribute flow or to use within the management agent, we have to handle this attribute differently. We set the value initially in clear text, however we actually handle changing the password after we insert the initial AxaptaRecord in a new table transaction session, looking up the new entry by the unique StaffID value we just populated.
axRec.Insert();//inserting initial attribute values ax.TTSBegin(); axRec.ExecuteStmt("select forupdate * from %1 where %1.StaffID == '" + csentry["RBOSTAFFTABLE.StaffID"].Value + "'")
Once we have our object selected, we can grab the cleartext password we inserted previously, encrypt the cleartext password using the Axapta method CallStaticClassMethod for the Dynamics X++ class "RBOUtils" and method "Encrypt" and set it on the object, all in one line. And updating the object and committing the transaction is merely a formality.
axRec.set_Field("Password", ax.CallStaticClassMethod("RBOUtils", "Encrypt", axRec.get_Field("Password").ToString())); axRec.Update(); ax.TTSCommit()
CallStaticClassMethod is a powerful method, as you can see. You can utilize Dynamics X++ methods from your MA. Very cool stuff.
This posting is provided "AS IS" with no warranties, and confers no rights.