In Dynamics AX, using the Business Connector, how do you call kernel functions?

核能气质少年 提交于 2019-11-28 01:24:03

问题


I would like to know how to call kernel functions from AX using C# (.Net Business Connector).

Specifically, can you call methods like fieldName2Id, tableName2Id and curUserId?


回答1:


I found some workarounds to calling kernel functions:

tableName2Id

(I was originally thinking of the tablenum method):


   //I used an extension method here  
   public static int GetTableId(this Axapta ax, string tableName)  
   {  
       return (int)ax.CallStaticClassMethod("Global", "tableName2Id", tableName);  
   }


curUserId


    //Another extension method  
    public static string CurUserId(this Axapta ax)  
    {  
        return (ax.CallStaticClassMethod("xUserInfo", "find") as AxaptaRecord).get_Field("Id").ToString();  
    }  


fieldName2Id

(I was originally thinking of the fieldnum method)


    //Another extension method  
    public static int GetFieldId(this Axapta ax, string tableName, string fieldName)  
    {  
        AxaptaObject dictionary = ax.CreateAxaptaObject("Dictionary");  
        int fieldId = 0;  
        if (ax.TableExists(tableName))  
        {  
            int tableId = ax.GetTableId(tableName);  
            AxaptaObject dictTable = (AxaptaObject)dictionary.Call("tableObject", tableId);  
            fieldId = (int)dictTable.Call("fieldName2Id", fieldName);  
        }  
        return fieldId;  
    }  

I hope this helps someone else!




回答2:


It's better to use:

Dictionary  dictionary = new Dictionary();
;
dictionary.tableName2Id(...);


来源:https://stackoverflow.com/questions/2861252/in-dynamics-ax-using-the-business-connector-how-do-you-call-kernel-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!