web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to consume oracle API in ax 2012 R3

(0) ShareShare
ReportReport
Posted on by 20

Hi All,

I want to consume oracle API in ax 2012 R3. Oracle team has provided me a URL so that I could consume that URL and access the JASON file available on it.

After accessing that JASON file I have to fill in the data from that JASON file to a staging table available in AX.

Please help with the process.I tried to google but not getting anything related to it.

Thanks

I have the same question (0)
  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: How to consume oracle API in ax 2012 R3

    As I said, I'm not familiar with the custom class you're using, but you can give it a try if you want.

    Create an extra data contract for the root object with those two properties. The type of 'data' will be list; you also must add AifCollectionTypeAttribute where you'll say which kind of data is in the list (TRICustGroupList class in your case). For example, look at how ERSolutionInfo class implements parmVersions().

  • Somesh Profile Picture
    55 on at
    RE: How to consume oracle API in ax 2012 R3

    Hi Martin,

    Thanks for your time and patience!!!

    Could you please guide me how can I parse the rawResponse directly to multiple objects??

    Thanks in advance..

  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: How to consume oracle API in ax 2012 R3

    No, unless it's hidden in TRICustGroupList class (which you didn't show us), you didn't write any code to do that. I've just explained that your code doesn't do anything.

    If I was you, I wouldn't try to extract those two substrings from rawResponse at all. I would parse rawResponse directly to multiple objects - a root object with properties success and data, where data is a collection of objects holding data about customer groups.

  • Somesh Profile Picture
    55 on at
    RE: How to consume oracle API in ax 2012 R3

    Thank you for the response Martin..

    Yes I need some logic to extract those two values from rawResponse so that I could store those values in table fields.

    I wrote the above code to achieve the same thing but it's not returniing the expected result.

    Could you please help how can I extarct those two values from rawresponse and store them in table.

  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: How to consume oracle API in ax 2012 R3

    Here I'm guessing what the method does - you still haven't shared this information with us.

    Let's say it receives a List objects, stores it in a variable and returns it back.

    Then this statement

    custGroupList.parmDataDetail(list)

    just returns what you already have in list.

    Then you iterate list, and because you put a single value there, rawResponse, it's what you get back. Therefore this code:

    rawResponse = response.parmData();
    custGroupList   = new TRICustGroupList();
    list            = new List(Types::String);
    list.addEnd(rawResponse);
    listIterator = new ListIterator(custGroupList.parmDataDetail(list));
    while (listIterator.more())
    {
    	custGroupContract = SMCFormJsonSerializer::deserializeObject(classIdGet(custGroupContract), listIterator.value());
    	listIterator.next();
    }

    Does the same thing as this:

    rawResponse = response.parmData();
    custGroupContract = SMCFormJsonSerializer::deserializeObject(rawResponse);

    Obviously that's not what you wanted.

    You need some logic to actually extract those two values from rawResponse.

  • Somesh Kumar Dubey Profile Picture
    20 on at
    RE: How to consume oracle API in ax 2012 R3

    Hi Martin,

    Thanks for the response..Could you please explain what do you mean when you said

    "If it's just a parameter method without any parsing, you'll get back the same value that you put there (= rawResponse) and the whole operations doesn't have any effect."

    Thanks

  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: How to consume oracle API in ax 2012 R3

    Yes, I know. Could you please read my previous reply once more and either follow it or tell me which part you don't understand?

  • Somesh Profile Picture
    55 on at
    RE: How to consume oracle API in ax 2012 R3

    Hi Martin, Thank you for the response.

    In rhe code snippet below .

    In rawResponse I am getting complete JSON string and I am trying to get the record one by one for each customerGroup through while loop but nits going in the loop only once however thre are multiple records in the JSON. Hence I want to retrieve both the records one by one.

    rawResponse = response.parmData();

      custGroupList   = new TRICustGroupList();

      list            = new List(Types::String);

      list.addEnd(rawResponse);

      listIterator = new ListIterator(custGroupList.parmDataDetail(list));

      while (listIterator.more())

      {

          custGroupContract    = SMCFormJsonSerializer::deserializeObject(classIdGet(custGroupContract), listIterator.value());

          info(strFmt('%1', custGroupContract.parmCustGroupId()));

          info(custGroupContract.parmCustGroupName());

          listIterator.next();

      }

    Thanks,

    Somesh

  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: How to consume oracle API in ax 2012 R3

    Your code expects that custGroupList.parmDataDetail() returns a List object with two JSON strings, one for each customer group. Unfortunately you didn't say whether it works or not, nor did you show the code.

    Look at the code and if the method isn't obviously wrong, use the debugger to check whether the method returns what you expect.

    If it's just a parameter method without any parsing, you'll get back the same value that you put there (= rawResponse) and the whole operations doesn't have any effect.

    By the please, use Insert > Insert Code (in the rich formatting view) to paste source code. It'll make it easier to read.

  • Somesh Profile Picture
    55 on at
    RE: How to consume oracle API in ax 2012 R3

    Sorry martin mistakenly i missed the no of line in the perivious code. I am attaching the code below.

    RetailWebRequest            request;

       RetailWebResponse           response;

       str                         rawResponse;

       RetailCommonWebAPI          webApi;

       Object                      deserializedContract;

       List                        list;

       ListIterator                listIterator;

       CreateCustGroupContract  custGroupContract;

       CustGroupList            custGroupList;

       webApi      = RetailCommonWebAPI::construct();

       request     = RetailWebRequest::newUrl("URL");

       response    = webApi.getResponse(request);

       rawResponse = response.parmData();

       custGroupList   = new TRICustGroupList();

       list            = new List(Types::String);

       list.addEnd(rawResponse);

       listIterator = new ListIterator(custGroupList.parmDataDetail(list));

       while (listIterator.more())

       {

           custGroupContract    = SMCFormJsonSerializer::deserializeObject(classIdGet(custGroupContract), listIterator.value());

           info(strFmt('%1', custGroupContract.parmCustGroupId()));

           info(custGroupContract.parmCustGroupName());

           listIterator.next();

       }

    Json String returned in rawResponse like below

    4274.Cap1.png

    {

    "success": true,

    "data": [

    {

    "CUST_GROUP_ID": 1,

    "CUST_GROUP_NAME": "Customer Group 1",

    "INSERT_FLAG": "Y",

    "RECORD_SENT_FLAG": "N",

    "ERROR_MESSAGE": null,

    "LAST_UPDATE_DATE": "2020-03-01T13:29:29.000Z",

    "LAST_UPDATED_BY": 0,

    "CREATION_DATE": "2020-03-01T13:29:29.000Z",

    "CREATED_BY": 0

    },

    {

    "CUST_GROUP_ID": 2,

    "CUST_GROUP_NAME": "Customer Group 2",

    "INSERT_FLAG": "Y",

    "RECORD_SENT_FLAG": "N",

    "ERROR_MESSAGE": null,

    "LAST_UPDATE_DATE": "2020-03-01T13:29:29.000Z",

    "LAST_UPDATED_BY": 0,

    "CREATION_DATE": "2020-03-01T13:29:29.000Z",

    "CREATED_BY": 0

    }

    ]

    }

    Thanks,

    Somesh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 745 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 597 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 580 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans