Issue in UPDATE Function - WEB Services

Ravi_Thakkar
Member Posts: 392
Hello,
In my testcases, UPDATE function of WEB SERVICE is not doing the Validation of other fields done from Coding part.
e.g.
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.
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.
0
Comments
-
Remember to set all other fields to null before update else the object will override the fields.0
-
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.0 -
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);0 -
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.0 -
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.0 -
Is there any updates regarding?0
-
Ravi_Thakkar wrote: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?0 -
Have you read this
http://blogs.msdn.com/freddyk/archive/2009/05/28/handling-sales-orders-from-page-based-web-services-in-nav-2009sp1-and-rtm.aspx
That should explain how you can overcome thisFreddy 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.0 -
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,
GD0 -
Hello Freddy,
Thanks for your response.freddy.dk wrote:Have you read this
http://blogs.msdn.com/freddyk/archive/2009/05/28/handling-sales-orders-from-page-based-web-services-in-nav-2009sp1-and-rtm.aspx
That should explain how you can overcome this
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 ?0 -
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.0 -
Hi freddy
I have applied your technique and have succeded to certain extent and these are my findings.please commentgulamdastagir wrote: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,
GD0 -
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.0 -
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?0 -
Ravi_Thakkar wrote: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?0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions