Issue in UPDATE Function - WEB Services

Ravi_ThakkarRavi_Thakkar Member Posts: 392
edited 2009-07-13 in NAV Three Tier
Hello,

In my testcases, UPDATE function of WEB SERVICE is not doing the Validation of other fields done from Coding part.
e.g.
private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Sales_Order_Service ss1 = new Sales_Order_Service();
            Sales_Order so1 = new Sales_Order();
            ss1.Url = "http://isplserver:7047/DynamicsNAV/WS/CRONUS_India_Ltd/Page/Sales_Order";

            ss1.UseDefaultCredentials = true;
            so1.No = textBox1.Text;
            so1 = ss1.Read("Order", so1.No);
            textBox3.Text = so1.Sell_to_Customer_No;
            textBox2.Text = so1.Sell_to_Post_Code;
            textBox4.Text = so1.Sell_to_City;            
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            Sales_Order_Service ss1 = new Sales_Order_Service();
            Sales_Order so1 = new Sales_Order();
            ss1.Url = "http://isplserver:7047/DynamicsNAV/WS/CRONUS_India_Ltd/Page/Sales_Order";

            ss1.UseDefaultCredentials = true;
            so1.No = textBox1.Text;
            so1 = ss1.Read("Order", so1.No);
       
            so1.Sell_to_Post_Code = textBox2.Text;
            ss1.Update(ref so1);
            textBox3.Text = so1.Sell_to_Customer_No;
            textBox2.Text = so1.Sell_to_Post_Code;
            textBox4.Text = so1.Sell_to_City;            
        
        }


Then If i go to update Sell-To Post Code field of Sales Header using Sales Order web service then logically it should update the Sell-To City field of the same record


But, It only updates the Post Code and leave City as it is.

So I want to make confirm whether I have done any mistake in my code or it's a bufg in Update Function of WEB SERVICE.

Please, help me urgently.
Thanks in advance.
Ravi_Thakkar
Ahmedabad, Gujarat, India
E Mail : ravi.thakkar@hotmail.com

Comments

  • mbjmbj Member Posts: 63
    Remember to set all other fields to null before update else the object will override the fields.
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    You sholdn't set fields to null - Web Services should be totally aware of what fields have changed and what not.
    I have just tried the following code:

    SalesOrder_Service service = new SalesOrder_Service();
    service.UseDefaultCredentials = true;
    SalesOrder so = service.Read("1017");
    so.Sell_to_Post_Code = "B68 5TT";
    service.Update(ref so);
    MessageBox.Show(so.Sell_to_City);

    and that works as expected - the city is updated.

    The confusing thing for me is your Read which takes two parameters? ("Order", so1.no)
    What is that?

    I just exposed page 42 to web services and then the above code runs.
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • mbjmbj Member Posts: 63
    Freddy.dk are you using a service pack? Because in my release of Nav 2009 i have to set all fields to null or Specified if the fields not are changed before update.

    In this case

    so1.Sell_to_Post_Code = textBox2.Text;
    so1.Sell_to_City = null ;
    ss1.Update(ref so1);
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    Sorry for the confusion.
    Yes, I was running a pre-release of NAV2009 SP1 and I didn't know that anything was fixed in this area at all.
    I tested on my RTM server and you are right:

    so1.Sell_to_Post_Code = textBox2.Text;
    so1.Sell_to_City = null ;
    ss1.Update(ref so1);

    will work (and I tested that this will work in SP1 as well).
    The null'ing of the city field shouldn't be necessary in SP1 though.
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Hello All,

    Thank you all for your replies.
    I got your point. I also thought the same.
    But, It is not a feasible sollution.

    For e.g.
    I open Sales Order having No. = 100 ,Sell-To Customer No. = 123, Sell-To Post Code = 123456.
    Now, If I want to update Customer No. then I will require to null all other fields except Sell-To Customer No.
    Now, I want to update Post Code then again I will have to do the same except for Sell-To Post Code.
    And such process would be very time consuming, and infeasible.

    If Any other sollution is there then please suggest.
    Thanks.
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Is there any updates regarding?
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Hello All,

    Thank you all for your replies.
    I got your point. I also thought the same.
    But, It is not a feasible sollution.

    For e.g.
    I open Sales Order having No. = 100 ,Sell-To Customer No. = 123, Sell-To Post Code = 123456.
    Now, If I want to update Customer No. then I will require to null all other fields except Sell-To Customer No.
    Now, I want to update Post Code then again I will have to do the same except for Sell-To Post Code.
    And such process would be very time consuming, and infeasible.

    If Any other sollution is there then please suggest.
    Thanks.

    Will this work?
    Is there any other option?
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • gulamdastagirgulamdastagir Member Posts: 411
    Hi Freddy

    we are big fan of your blogs here in australia.The code to run in NAV 2009 RTM (which i copied from your blog directly)would give me two types of errors
    1.Sell to Customer No cannot be Blank is sales header as the PrepareforUpdate method also nulls the "Sell to Customer No ".Therefor iam calling PrepareforUpdate() and then Sellto Customer No="10000"; and then service.update(ref neworder) as shown in modified code below
    2.After Modifying the code as shown below i am able to create the Sales Orders in NAV 2009 successully.However it doesnt update the Quantity=3; part of the code.I even tried to make it Quantity=3.0m; as quantiy is decimal not integer but why doesnt it update the Quantity even then?




    static void Main(string[] args)
    {



    //create service references

    SalesOrder_Service service = new SalesOrder_Service();
    service.UseDefaultCredentials = true;
    service.Url = "http://ac-dc:7047/DynamicsNAV/WS/CRONUS_Australia_Pty_Ltd/Page/SalesOrder";

    SalesOrder newOrder = new SalesOrder();
    service.Create(ref newOrder);

    //*
    SalesOrder copy = (SalesOrder)(newOrder);

    PrepareForUpdate(newOrder, copy);
    newOrder.Sell_to_Customer_No = "10000";
    service.Update(ref newOrder);
    copy = (SalesOrder)GetCopy(newOrder);


    PrepareForUpdate(newOrder, copy);


    newOrder.SalesLines = new Sales_Order_Line[2];
    for (int idx = 0; idx < 2; idx++)
    {
    newOrder.SalesLines[idx] = new Sales_Order_Line();
    }

    Sales_Order_Line line1 = newOrder.SalesLines[0];
    line1.Type = SO.WebService.Type.Item;
    line1.No = "1900-S";
    line1.Quantity = 3;
    line1.Description = "GD ITEM1 SSSS";



    Sales_Order_Line line2 = newOrder.SalesLines[1];
    line2.Type = SO.WebService.Type.Item;
    line2.No = "1000";
    line2.Description = "GD ITEM2S UIJJJK";
    line2.Quantity =3;

    service.Update(ref newOrder);



    Console.WriteLine("Created Sales Orders");
    Console.ReadKey();






    }
    }
    }
    Regards,

    GD
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Hello Freddy,
    Thanks for your response.
    freddy.dk wrote:
    Yes, I have already read your well prepared Blogs.
    But, I think you have written about some UPDATE functionality related to NAV 2009 SP1.
    And I think SP1 is not released yet. Am I right here????? :?: :?:

    Can I use the same update functionality for NAV 2009 ?
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    Correct, but the post also describes a way to avoid having to NULL all fields in pre-sp1.
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • gulamdastagirgulamdastagir Member Posts: 411
    Hi freddy

    I have applied your technique and have succeded to certain extent and these are my findings.please comment

    Hi Freddy

    we are big fan of your blogs here in australia.The code to run in NAV 2009 RTM (which i copied from your blog directly)would give me two types of errors
    1.Sell to Customer No cannot be Blank is sales header as the PrepareforUpdate method also nulls the "Sell to Customer No ".Therefor iam calling PrepareforUpdate() and then Sellto Customer No="10000"; and then service.update(ref neworder) as shown in modified code below
    2.After Modifying the code as shown below i am able to create the Sales Orders in NAV 2009 successully.However it doesnt update the Quantity=3; part of the code.I even tried to make it Quantity=3.0m; as quantiy is decimal not integer but why doesnt it update the Quantity even then?




    static void Main(string[] args)
    {



    //create service references

    SalesOrder_Service service = new SalesOrder_Service();
    service.UseDefaultCredentials = true;
    service.Url = "http://ac-dc:7047/DynamicsNAV/WS/CRONUS_Australia_Pty_Ltd/Page/SalesOrder";

    SalesOrder newOrder = new SalesOrder();
    service.Create(ref newOrder);

    //*
    SalesOrder copy = (SalesOrder)(newOrder);

    PrepareForUpdate(newOrder, copy);
    newOrder.Sell_to_Customer_No = "10000";
    service.Update(ref newOrder);
    copy = (SalesOrder)GetCopy(newOrder);


    PrepareForUpdate(newOrder, copy);


    newOrder.SalesLines = new Sales_Order_Line[2];
    for (int idx = 0; idx < 2; idx++)
    {
    newOrder.SalesLines[idx] = new Sales_Order_Line();
    }

    Sales_Order_Line line1 = newOrder.SalesLines[0];
    line1.Type = SO.WebService.Type.Item;
    line1.No = "1900-S";
    line1.Quantity = 3;
    line1.Description = "GD ITEM1 SSSS";



    Sales_Order_Line line2 = newOrder.SalesLines[1];
    line2.Type = SO.WebService.Type.Item;
    line2.No = "1000";
    line2.Description = "GD ITEM2S UIJJJK";
    line2.Quantity =3;

    service.Update(ref newOrder);



    Console.WriteLine("Created Sales Orders");
    Console.ReadKey();






    }
    }
    }
    Regards,

    GD
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    I am pretty sure that the code in my blog runs in RTM without modifications.
    I do not have a RTM installation right now, so I cannot test it - but it seems like you have removed some lines.

    Basically for every time you call service.update - you need to call prepareforupdate before service.update and getcopy after - and then use whatever you got from getcopy to work with.

    That should work....

    (note the very political: should!)
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Hello Freddy,

    Thanks for your reply.
    Really a great job done in Blog and Logic for Updating the Values. Great. =D> =D> =D>

    Whether the Concurrency in updating the Fields by the Method specified by you in Blog, handled by System automatically or need to be handled Manually?
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Hello Freddy,
    Whether the Concurrency in updating the Fields by the Method specified by you in Blog, handled by System automatically or need to be handled Manually?
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
Sign In or Register to comment.