Using functions in Odata Webservices

AitorEGAitorEG Member Posts: 342
Hi everyone,

I am creating an extension for integrating via REST webServices with an external application.
First of all, I've created a simple table:
fields
    {
table 50701 "KanbanizeCard"
.....
        field(1; "ID"; Integer)
        {
            Caption = 'ID';
            DataClassification = ToBeClassified;
        }
        field(2; "Nombre"; Text[200])
        {
            Caption = 'Nombre';
            DataClassification = ToBeClassified;
        }
    }
I've published a page for this table as a WebService, and created this function:
}
    [ServiceEnabled]
    procedure AddCard(var actionContext: WebServiceActionContext)
    var
        card: Record KanbanizeCard;
        ODataActionManagement: Codeunit "OData Action Management";
    begin
        ODataActionManagement.AddKey(Rec.FieldNo(ID), Rec.Nombre);
        card.Get(Rec.ID);
        card.Nombre := 'clip';
        card.Modify();
    end;
And I'm calling with post, to this URL:
https://api.businesscentral.dynamics.com/v2.0/xxxxxx-e780-4167-8bff-xxxxxx/SandboxKANBANIZE/ODataV4/Company('CRONUS ES')/KanbanCard(33888)/NAV.AddCard()

The result is not bad, I get the record with 33888 key, and the 'nombre' field is changed to 'clip'.
BUt of course, the goal of this development is to send the new 'nombre' as parameter, not fixed into the code.
How can be this made? I'm reading about this issue, boundary actions and all that, but I don't understand how to define correctly the objets, and how to make the call to the URL... Probably somethin with the actioncContext and OdataActionManagement, but I'm lost.

Any hint will be really appreciated



Answers

  • TallyHoTallyHo Member Posts: 417
    Publishing a page will result in consuming odata.
    Read about the possibilities for passing filters here.
    https://docs.microsoft.com/en-us/odata/concepts/queryoptions-usage

    'Misusing' a filter value can give you the possibility to pass 'clip' as a variable.
    But normally you would use soap or API services for manipulating data, and odata for
    just querying it.
  • AitorEGAitorEG Member Posts: 342
    Thanks for your answer @TallyHo,
    I understand what you say about better using SOAP, but I think is one of the requisites of the external app using REST.
    What do you mena with "misusing" the filter to pass clip as variable?

  • TallyHoTallyHo Member Posts: 417
    Don't remember exactly but if you put in $filter in your URL and filter on 'clip' using the odata standard you can get the filtervalue OnFindRecord trigger of your page.
    Put the filter in a text variable using getfilter on your dataitem.
    Reset all filters, and execute your own logic with the text string.
  • AitorEGAitorEG Member Posts: 342
    The issue more than filtering, is that I need to pass as parameter foe exameple, a text, to modify the record into database.
    Filtering issue seems to be solved. The thing is to send a text for modifying the record. And not just a text, probably in a near future must receive a jSon, and process it.
  • TallyHoTallyHo Member Posts: 417
    I understood you perfectly, I faced the same problem. But solved it by adding fields and filters just for the purpose of sending variables. It's a very creative solution, I'd better not recommend it.

  • AitorEGAitorEG Member Posts: 342
    Thanks for your tips TallyHo.
    Glad to ear that you solved this issue, I understand what you say about not recommending it, it should be better SOAP...
    Ypu solved it sending the fields and filters by URL??
  • TallyHoTallyHo Member Posts: 417
    Yes solved it sending the fields and filters URL.
    added fields to the table just for the purpose.
    Misused getfilter to get my parameters/data. Resetted all filters after the call, and
    continued my own way through c/al coding.
    But it whas to create a link with a call log for ip phone server.
    Nothing shocking.
  • AitorEGAitorEG Member Posts: 342
    And how was the URL looking? I understand that you weren't using boundary actions,. am I right?
  • TallyHoTallyHo Member Posts: 417
    $filter='Phone No.' IS %phone%"
    This is what was added to the url
  • AitorEGAitorEG Member Posts: 342
    Thanks TallyHo, I'll work on it!
  • AitorEGAitorEG Member Posts: 342
    Hi @TallyHo,

    When you pass that paremeter from a IRL, you are using directly the oData URL of a page, or you are refering to a boundary action, and calling it as a funtion, like for exameple, tthis:

    https://api.businesscentral.dynamics.com/v2.0/xxxxx-e780-4167-8bff-xxxxxx/SandboxKANBANIZE/ODataV4/Company('CRONUS ES')/KanbanCard(33888)/NAV.AddCard()

    How do you get or process those parameters into the page?
    Sorry for all this question, but I'm trying to integrate with a 3rd partner software, and using REST is mandatory,,,,
  • TallyHoTallyHo Member Posts: 417
    Try publishing your page in the webservices section, and use the url suggested there
  • AitorEGAitorEG Member Posts: 342
    Interesting.. So using "normal" Odata.
    With that URL you are "atacking" customer pageno? What is the goal of that URL? And in the page how did you proceess the parameters?
  • TallyHoTallyHo Member Posts: 417
    No this was a NAV query object published in webservices. Easier to use odata query language on that. But it has to be possible to achieve the same with a published page, odata is odata. But looking into a published page I can see your trouble now. The results are all messed with links and bookmarks.

    The way I went about for the phone link was calling the page through a direct call to the webclient created a page especially for the purpose (forgot about that, sorry). This way I could enter the filters the same way I did it in my example of the published query Cust. So Odata querying works for direct calls to a specific page in the web client too.
  • AitorEGAitorEG Member Posts: 342
    Thanks for your tips,really appreciated.
    This week I will have a development meeting with the externela application developer, we'll see if we can achieve something interesting...
Sign In or Register to comment.