Adding an order by XMLPORT, CODEUNIT

naranara Member Posts: 37
Hi,
I am not that experienced in Navision so I need some advise from you EXPERTS.
I have th following task:
I have to develope a .NET application that can retrieve Items, Contacts from NAvision and deliver Sales order to Navision, I did managed the first part but I have problem with delivering sales orders.

I have the following XML( just a example but the format is right )
<SalesOrder>
- <SalesHeader>
<OrderDate>14-02-08</OrderDate>
- <BillTo>
<CustomerNo>43687129</CustomerNo>
<Name>nasser tester</Name>
<City>Bergen</City>
<PostCode>5232</PostCode>
</BillTo>
- <ShipTo>
<Name>nasser tester</Name>
<Address>Kloppedalsveien 5</Address>
<City>Bergen</City>
<PostCode>5232</PostCode>
</ShipTo>
</SalesHeader>
- <SalesLines>
- <Line>
<ItemID>1900</ItemID>
<Description>Ramme</Description>
<UnitPrice>50</UnitPrice>
<Quantity>2</Quantity>
</Line>
</SalesLines>
</SalesOrder>

I did made a XMLPORT the maches this XML-hierachy which will try to insert data into SalesHeader and SalesLine tables, I did compiled my XMLPORT, no problem.
I did create a code unit to test this XMLPORT:

iFile.OPEN('c:\XMLTest\NEttsalg\SaleOrderTest.xml');
iFile.CREATEINSTREAM(iStream);
XMLPORT.IMPORT(50002,iStream);
iFile.CLOSE;

But when I try to run this CODEUNIT so I get the following error message alert

the following C/AL functions can be used only to a limited degree during write transactions
(because one or more tables will be locked)

Form.RunModal() is not allowed in write transactions.

CodeUnit.Run() is allowed in write transactions only if the return value is not used. For example, 'OK :=CodeUnit.RUn()' is not allowed.

Report.RunModal() is allowed in write transactions only if 'RequestForm = FALSE'.
For example,'Report.RunModal(...,FALSE)' is allowed.

DataPort.RunModal() is allowed in write transactions only if 'RequestForm = FALSE'.
For example, 'DataPort.RunModal(...,FALSE)' is allowed.

Use the COMMIT function to save the changes before this call, or structure the code differently.


Any Idea about what I do wrong!?

best regards nara

Comments

  • girish.joshigirish.joshi Member Posts: 407
    My guess is that one of the fields you are validating has form.runmodal on it.

    Instead of writing your own XML port, have you considered using the standard CG Sales Header XMLPort?
  • kinekine Member Posts: 12,562
    If you enable debugger, you will see where the error is raised. It will be som code opening form or running report with requestform. This cannot be done when writing transaction was already started.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • naranara Member Posts: 37
    Thank you both for your advise.
    I can't find the XMLPORT that you mentined!
    I did turned on debugging, problem was in mismatch between postcode and City, but I do get this message( the original message is Norwegian ) but here is the translation
    Standard text code 1900 dose'nt exists!

    Any Idea?
  • kinekine Member Posts: 12,562
    It seems that you are validating "No." field before you set the correct "Type" fild option (is empty now and NAV assume Standard text code in "No." field). Fill the Type field fist (by Item value etc.).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • naranara Member Posts: 37
    I believe you are absolutely right, I did see the problem right after I did posted my problem. I did try to put a value fro column No_ from table Item.

    Thanks again, I will try :).
  • naranara Member Posts: 37
    I realy messed up now, I am confused.
    Now I get this error message, translated to english:
    There is no Foreign exchange quotation in filter.
    Filter: ExchangeCode: EUR, StartDate: "..".

    Her is my XML and I am trying to add some rows to Sales Header and Sales Line Tables
    - <SalesOrder>
    - <SalesHeader>
    <DocType>1</DocType>
    <OrderDate>18-02-08</OrderDate>
    <SellTo>43687129</SellTo>
    - <BillTo>
    <CustomerNo>43687129</CustomerNo>
    <Name>Designstudio Gmunden</Name>
    <City>Gmunden</City>
    <PostCode>AT-4810</PostCode>
    </BillTo>
    - <ShipTo>
    <Name>Designstudio Gmunden</Name>
    <Address>Seepromenade 1b</Address>
    <City>Gmunden</City>
    </ShipTo>
    </SalesHeader>
    - <SalesLines>
    - <Line>
    <Type>2</Type>
    <ItemID>1924-W</ItemID>
    <Description>CHAMONIX basisreol</Description>
    <UnitPrice>1330</UnitPrice>
    <Quantity>7</Quantity>
    </Line>
    </SalesLines>
    </SalesOrder>

    Last friday I did managed to make this XML to work but I did changed some thing in my XML and now nothing work!!!! :oops: :? ](*,) #-o
Sign In or Register to comment.