Recently I received a question about calling global objects in BC and thought others may have similar question as well, so sharing the answer here.

Question:

I am creating object of Global Class of Axapta in C# code via AxConnectionObject.CreateObject(“Globla”,………….); API.

The object is getting created well. But then I want to call the static API enum2Value() of Global Class. This call fails with Error “The Object does not contain the API enum2Value” Q:
I am facing one problem with Global Class.
I also tried with other APIs of Global Class but the same error. Is it due to static API.

Ideally the API’s of Global class are static so no need to create Global Object but then how can we access it in C# code. Is there any other way? PLZ help me ASAP this is a blocking issue.

  IAxaptaObject objGlobalClass = objConnection.Connection.CreateObject("Global", null, null, null, null, null, null);
      // Object created with No errors.
      if (objGlobalClass != null)
          {
          
                   object objBaseTypeEnum =  objAxField.Call("baseType", null, null, null, null, null, null);
                   object objBaseType = objGlobalClass.Call("enum2Value", objBaseTypeEnum, null, null, null, null, null);
                   //Here excaption comes that Object does not contains method enum2Value !!
                            //if (objBaseType != null)
                           //    strFieldBaseType = objBaseType.ToString();
         }

Answer:

It is mentioned below that the methods being called are static and "Call” method is being used in the above example, this could be the cause of the problem; “CallStaticMethod” should be used for static methods and BC documentation on MSDN has example on that.