{"id":519,"date":"2012-09-12T13:47:06","date_gmt":"2012-09-12T13:47:06","guid":{"rendered":"http:\/\/foxware.co.uk\/?p=519"},"modified":"2012-09-12T14:05:18","modified_gmt":"2012-09-12T14:05:18","slug":"ax-bc-call-a-static-method","status":"publish","type":"post","link":"http:\/\/foxware.co.uk\/?p=519","title":{"rendered":"AX BC &#8211; Call a Static Method"},"content":{"rendered":"<p>&nbsp;<\/p>\n<pre class=\"lang:c# decode:true\">\tAxapta ax;\r\n            Object axObject;\r\n            try\r\n            {\r\n                \/\/ Create a new Axapta object.\r\n                ax = new Axapta();\r\n                \/\/ Logon using the default settings\r\n                \/\/ in the AX configuration for the .NET\r\n                \/\/ Business Connector\r\n                ax.Logon(null, null, null, null);\r\n                \/\/ Call the static method and return the\r\n                \/\/ result to the axObject variable\r\n                axObject =\r\n                  ax.CallStaticClassMethod(\"Global\", \"AxHelloWorld\");\r\n                \/\/ Print the result to the console\r\n                Console.WriteLine(\"The message from AX is {0}\",\r\n                  axObject.ToString());\r\n                ax.Logoff();\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                Console.WriteLine(e.Message);\r\n            }<\/pre>\n<p>Another good example for finding a record ID by calling the standing find method from a table<\/p>\n<pre class=\"lang:c# decode:true\">ax.CallStaticClassMethod(\"xUserInfo\", \"find\") as AxaptaRecord).get_Field(\"Id\").ToString()<\/pre>\n<p>And another&#8230;<\/p>\n<pre>    public static int GetFieldId(this Axapta ax, string tableName, string fieldName)  \r\n    {  \r\n        AxaptaObject dictionary = ax.CreateAxaptaObject(\"Dictionary\");  \r\n        int fieldId = 0;  \r\n        if (ax.TableExists(tableName))  \r\n        {  \r\n            int tableId = ax.GetTableId(tableName);  \r\n            AxaptaObject dictTable = (AxaptaObject)dictionary.Call(\"tableObject\", tableId);  \r\n            fieldId = (int)dictTable.Call(\"fieldName2Id\", fieldName);  \r\n        }  \r\n        return fieldId;  \r\n    }<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Axapta ax; Object axObject; try { \/\/ Create a new Axapta object. ax = new Axapta(); \/\/ Logon using the default settings \/\/ in the AX configuration for the .NET \/\/ Business Connector ax.Logon(null, null, null, null); \/\/ Call &hellip; <a href=\"http:\/\/foxware.co.uk\/?p=519\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/foxware.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/519"}],"collection":[{"href":"http:\/\/foxware.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/foxware.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/foxware.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/foxware.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=519"}],"version-history":[{"count":5,"href":"http:\/\/foxware.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/519\/revisions"}],"predecessor-version":[{"id":526,"href":"http:\/\/foxware.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/519\/revisions\/526"}],"wp:attachment":[{"href":"http:\/\/foxware.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/foxware.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=519"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/foxware.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}