Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

SalesLines object set to null after update

Posted on by Microsoft Employee

I've got old console app that imports order items to MS-dynamic-nav 2009. It worked before but one day stopped working and I'm not sure why. I've debugged and found that after service.Update all SalesLine become null even if they were initialized before

SalesOrder_PortClient client = new SalesOrder_PortClient(NAVConnect.GetBinding(),NAVConnect.GetEndPointAddress("address"));
NAVConnect.NAVWSConnect<SalesOrder_Port>(client);
SalesOrder so = new SalesOrder();
client.Create(ref so);

so.Sell_to_Customer_No = items.First().CustomerNumber;
so.Shipment_Date = items.First().ShipmentDate;
so.External_Document_No = items.First().ExternalDocumentNumber;
so.Shipping_Agent_Code = items.First().ShippingAgent;
client.Update(ref so);

so.SalesLines = items.Select(x=>new Sales_Order_Line()).ToArray();
// SalesLines NOT NULL
client.Update(ref so);
// SalesLines BECOMES NULL
for (int i = 0; i < items.Length; i++)
{
    // HERE NullReferenceException
    so.SalesLines[i].No = items[i].ItemNumber;
    so.SalesLines[i].Quantity = items[i].Quantity;
    so.SalesLines[i].Unit_of_Measure_Code = items[i].UOM;
    so.SalesLines[i].Type = SalesOrderWS.Type.Item;
}
client.Update(ref so);

Because of that I'm getting NullReferenceException

Anyone can help?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SalesLines object set to null after update

    Hi Zaid,

    At line #5 in your suggested solution

    so.SalesLines[i]=new Sales_Order_Line();

    there would be a NullReferenceException, because so.SalesLines is NULL after Update at line#2

  • Zaid Tariq Profile Picture
    Zaid Tariq 2,266 on at
    RE: SalesLines object set to null after update

    Sure, No problem. Just ping me any :)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SalesLines object set to null after update

    Hello Zaid,

    Thanks a lot for you reply.

    Yes you are right I'm getting this using SOAP Webservice.

    I tried the way you suggested before but got another error at Update action in for-cycle as far as I remember. At the moment I don't have access to environment to provide exception details. But will do as soon as possible during next days.

  • Zaid Tariq Profile Picture
    Zaid Tariq 2,266 on at
    RE: SalesLines object set to null after update

    Hi @vlc-it!

    Once i had the same problem while inserting into NAV using SOAP webservice. I see the similar problem with your code too. Can you please try something like this?

    so.SalesLines = items.Select(x=>new Sales_Order_Line()).ToArray();
    client.Update(ref so);
    for (int i = 0; i < items.Length; i++)
    {
        so.SalesLines[i]=new Sales_Order_Line();
        so.SalesLines[i].No = items[i].ItemNumber;
        so.SalesLines[i].Quantity = items[i].Quantity;
        so.SalesLines[i].Unit_of_Measure_Code = items[i].UOM;
        so.SalesLines[i].Type = SalesOrderWS.Type.Item;
        client.Update(ref so);
    }
    


    Please let me know is still have problem. Thanks

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SalesLines object set to null after update

    Thank you for reply.

    Sorry, I did not understand your suggestion.

    The program is pretty simple and I've posted most of the code here.

    So flow works next way:

    1. Read the file

    2. Create OrderItem from each line of file

    3. Start method ImportOrder (all code of method posted at first message)

    Also situation is that It worked before but one day suddenly stopped working. Not sure why.

    I also found an article where code looks very similar to this but It is not working for me:

    blogs.msdn.microsoft.com/.../extending-page-web-services-and-creating-a-sales-order-again

  • Maneesha Profile Picture
    Maneesha 5,889 on at
    RE: SalesLines object set to null after update

    have yo done any changes to Line tab

    any mandatory field except

    No

    Quantity

    Unit_of_Measure_Code

    Type

    and can you check and do any order by manually

    with only update the that you import from your console and try "post"  and check whether is it post or not  

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SalesLines object set to null after update

    Hi Maneesha,

    Thanks for your reply. I'm using Console app in C#. Reading items from .txt flat file

  • Maneesha Profile Picture
    Maneesha 5,889 on at
    RE: SalesLines object set to null after update

    Hi vlc-lt  ,

    How did you import this ??

    EXE via Task scheduler ?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans