Hello,
I try to Change a Class Method in X++ code. I write the following code:
#AOT
ClassName className = classStr(Class1);
TreeNode classLayerVersionTreeNode, classLayerVersion;
Source layerVersion;
date now;
;
classLayerVersion = TreeNode::findNode(strFmt(@"%1\%2",#ClassesPath, className));
classLayerVersion.AOTrestore(true);
classLayerVersionTreeNode = TreeNode::findNode(strFmt(@"%1\%2\%3",#ClassesPath, className, #MethodName));
classLayerVersionTreeNode.AOTrestore(true);
layerVersion = strFmt("static str layerVersion() \r\n { \r\n return '%1-%2'; \r\n }",strUpr(strFmt("%1",Global::currentAOLayer())), date2str(today(),321,DateDay::Digits2,DateSeparator::None,DateMonth::Digits2,DateSeparator::None,DateYear::Digits4));
classLayerVersionTreeNode.AOTsetSource(layerVersion, false);
classLayerVersionTreeNode.AOTsave();
classLayerVersionTreeNode.AOTcompile();
classLayerVersion = TreeNode::findNode(strFmt(@"%1\%2",#ClassesPath, className));
classLayerVersion.AOTsave();
classLayerVersion.AOTcompile();
This code works fine while i call it from a Job in AX Client and Change the Method in VAR Layer as expected.
Now I want to call this method to Change the Code within a ConsoleApplication (in Future a Windows Forms application) with this code:
static void Main(string[] args)
{
proxy.Axapta DynAx = new proxy.Axapta();
string info = "N/A";
try
{
DynAx.Logon(null, null, null, @"D:\Config2012\DAX2012R3EntwVAR.axc");
Console.WriteLine("Verbunden");
info = (string)DynAx.CallStaticClassMethod("Class", "changeCode");
Console.WriteLine(info);
DynAx.Logoff();
Console.WriteLine("beendet");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
}
The Result of this is, the code will Change, but it was changed in USR - Layer, not in VAR layer. The Config File for Logon ist specifed for VAR-Layer and within the AX-Code at Position ... strFmt("%1",Global::currentAOLayer()... knows the correct - VAR - Layer. So why are the Changes for the Code at USR - Layer after I run the ConsoleApplication?