Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Pass value from codeunit to XMLPort

(0) ShareShare
ReportReport
Posted on by 271

Hi,

I have a Code Unit where using webservice i receive some parameters and i turn back some values.

Simulador(ContactNo : Code[20];ItemNo : Code[20];VAR CustName : Text[50];VAR PmtTermsCode : Code[20];VAR ItemDesc : Text[50];VAR Vas : Integer;VAR Vasi : XMLport Vasilhames) : Text

ltBusRel.RESET;
ltBusRel.SETRANGE("Contact No.",ContactNo);
ltBusRel.SETRANGE("Business Relation Code",'CLI');
IF ltBusRel.FINDFIRST THEN
BEGIN
ltCustomer.GET(ltBusRel."No.");
ltPaymentTerms.GET(ltCustomer."Payment Terms Code");
END; 
ltitem.RESET;
ltitem.SETRANGE("No.",ItemNo);
IF ltitem.FINDFIRST THEN
BEGIN
Descricao:=ltitem."Extended Description";
ItemContainer.RESET;
ItemContainer.SETRANGE("Item No.",ItemNo);
IF ItemContainer.FINDSET THEN 
BEGIN REPEAT
Vasilhame:=ItemContainer.COUNT;
UNTIL ItemContainer.NEXT=0;
END;

END;
Vas:=Vasilhame;


This function counts the number of item cointainer of a product and all the item containers.
What i want is how to filter for one item?

In XMLPort or in the Codeunit and how?

This is my xml

Node Name Prefix Node Type Source Type Data Source
XMLComentariosCompra Element Text <XMLComentariosCompra>
Vasilhame Element Table <Item Container>(Item Container)
No Element Field Item Container::Container No.

Can someone help me please? Thanks

*This post is locked for comments

  • Rikarddo Profile Picture
    Rikarddo 271 on at
    RE: Pass value from codeunit to XMLPort

    Please some help?

    I have codeunit published as webservice. In that codeunit i call other codeunit that calculates some value.

    Simulador(ItemNo : Code[20];ItemContainerNo : Code[20];VAR xml : XMLport PricingToolSimulador;VAR Temp : Decimal)
    ....
    Temp:=PricingTool.GetCustoOperacao(ItemNo,Variante);

    ItemNo and Variante are parameters. Fine so far.

    My final goal is:

    I have an xmlport not based in any table. I have a variable CostOp that will export the the same value as show above

    CustoOp:=format(PricingTool.GetCustoOperacao(ItemNo,Variante));

    My dificulty here is how to pass to xmlport the Itemno and variante in the webservice codeunit??

    If i make like this CustoOp:=format(PricingTool.GetCustoOperacao('0000001010','j70-1010')); it will return a tag with
    the correct value.


    Will apreciate some tips thanks
  • Rikarddo Profile Picture
    Rikarddo 271 on at
    RE: Pass value from codeunit to XMLPort

    I will try to explain,

    This function will simulate some costs depending on the values that will get. For example for Item A and Variant Y it must read on a specific table that cost and return it. As the code shows below

    ...
    
    ltitem.RESET;
     ltitem.SETRANGE("No.",ItemNo);
     IF ltitem.FINDFIRST THEN
     BEGIN
      Descricao:=ltitem."Extended Description";
      ItemContainer.RESET;
      ItemContainer.SETRANGE("Item No.",ItemNo);
      ItemContainer.SETFILTER(Quantity,'<>%1',0);
      IF ItemContainer.FINDSET THEN 
      BEGIN REPEAT
    ...

       OperationCost:=PricingTool.GetCustoOperacao(ItemNo,Variante);

    This is calculating and passing the cost by reference. I want to use a specific XMLPort called PricingTool that has all the variables that i want to pass and return in a xml file.

    My difficulty here is how to use that xmlport and where to call my function after published as webservice.

    For now my xml:

    Node Name Prefix Node Type Source Type Data Source
    LinesPricingTool Element Text <LinesPricingTool>
    OperationCost Element Text <CostOp>

    In my xml i should type something like:

    lcPricingTool.GetCustoOperacao(Parameters); or call my function in the webservice?

    I don't know if i am explaining well my goal here, or if you're understanding it

  • Rikarddo Profile Picture
    Rikarddo 271 on at
    RE: Pass value from codeunit to XMLPort

    Got it!

    Here is my code working

    Simulador(ContactNo : Code[20];ItemNo : Code[20];VAR CustName : Text[50];VAR PmtTermsCode : Code[20];VAR ItemDesc : Text[50];VAR Vas : Integer;VAR Vasi : XMLport Vasilhames) : Text
     ltBusRel.RESET;
     ltBusRel.SETRANGE("Contact No.",ContactNo);
     ltBusRel.SETRANGE("Business Relation Code",'CLI');
     IF ltBusRel.FINDFIRST THEN
     BEGIN
      ltCustomer.GET(ltBusRel."No.");
      ltPaymentTerms.GET(ltCustomer."Payment Terms Code");
     END; 
     ltitem.RESET;
     ltitem.SETRANGE("No.",ItemNo);
     IF ltitem.FINDFIRST THEN
     BEGIN
      Descricao:=ltitem."Extended Description";
      ItemContainer.RESET;
      ItemContainer.SETRANGE("Item No.",ItemNo);
      ItemContainer.SETFILTER(Quantity,'<>%1',0);
      IF ItemContainer.FINDSET THEN 
      BEGIN REPEAT
         Vasilhame:=ItemContainer.COUNT;
         Vasi.SETTABLEVIEW(ItemContainer);    <---- How got it working  --- is that ok?
      UNTIL ItemContainer.NEXT=0;
      END;
         
     END;
    Vas:=Vasilhame;
    CustName := ltCustomer.Name;
    PmtTermsCode := ltCustomer."Payment Terms Code";
    ItemDesc := Descricao;


  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,614 on at
    RE: Pass value from codeunit to XMLPort

    If you publish that codeunit as the the webservice that function is available for other applications  to use, what is your real requirement ? Why did you create that function ?

  • Rikarddo Profile Picture
    Rikarddo 271 on at
    RE: Pass value from codeunit to XMLPort

    That's my doubt, where shall i use that function and how to call it?

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,614 on at
    RE: Pass value from codeunit to XMLPort

    In your function you already have the Item No. filter to filter for a specific Item, are you not using that function to call ?  can you please share your code how you calling the function ?  

  • Suggested answer
    Andrey Baludin Profile Picture
    Andrey Baludin 3,941 on at
    RE: Pass value from codeunit to XMLPort

    Hi!

    1. You have ItemNo parameter in your function. And after that you filters items by it.

    2. OFFTOPIC. Please change this code:

    IF ItemContainer.FINDSET THEN 
    BEGIN 
      REPEAT
        Vasilhame:=ItemContainer.COUNT;
      UNTIL ItemContainer.NEXT=0;
    END;


    To this code (you don't need to use repeat cycle):

    IF ItemContainer.FINDSET THEN 
      Vasilhame:=ItemContainer.COUNT;
    


    3. This is an example of passing filter to webservice function and getting back filtered value with xmlport:

    GetItemInfo(ItemNo : Code[20];VAR ItemInfo : XMLport "Item Info")
    
    Item.SETRANGE("No.", ItemNo);
    Item.FINDFIRST;
    ItemInfo.SETTABLEVIEW(Item);
    


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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,492 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans