Use fields dynamicly in webservices
 
            
                
                    Kaiawaia                
                
                    Member Posts: 6                
            
                        
            
                    Hello,
is it possible to access fields dynamicly? For example, I want to write a
value to a field. But I know which field this is only at runtime. I think for something like
this example shows:
account testContact = new Contact();
testAccount.Fields["City"] = "Berlin";
There is no "Fields" in Contact. That's only an example to show
what I mean. Is there any possiblility to use fields in this way?
Thanks,
Kai
                is it possible to access fields dynamicly? For example, I want to write a
value to a field. But I know which field this is only at runtime. I think for something like
this example shows:
account testContact = new Contact();
testAccount.Fields["City"] = "Berlin";
There is no "Fields" in Contact. That's only an example to show
what I mean. Is there any possiblility to use fields in this way?
Thanks,
Kai
0                
            Comments
- 
            You can use recordreference and fieldreference to do that.Regards,Alain Krikilion
 No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
- 
            what Alain means is that you can use a publish a CU function and pass the parameters to update a field at runtime.
 In that function you can use recordref and fieldref variables
 You cannot do this through publishing pages as webservices.0
- 
            Thanks for your replies. I will try with the references. That doesn't sound bad.0
- 
            Hello,
 We can use the Codeunit logic as here specified. But, as the Microsoft Help on Web Services, transactions done using Codeunit functions will require Concurrency to be managed manually.ara3n wrote:what Alain means is that you can use a publish a CU function and pass the parameters to update a field at runtime.
 In that function you can use recordref and fieldref variables
 You cannot do this through publishing pages as webservices.
 So, by using this method, Concurrency may become an issue.0
- 
            Concurrency is always an issue, and every developer who developers in NAV needs to manage it in code. If two people are modifying the same record, the user should get an error that somebody else has modified the record.
 The bigger issue is managing transactions. Each call to a cu is a separate transaction. so you need to pay attention how transaction are committed and rolled back.0
- 
            If you want to assign fields dynamically from c# - you can use reflection to do that, in fact you can have web service reference be totally dynamic as explained here:
 http://blogs.msdn.com/freddyk/archive/2009/04/27/dynamic-references-to-nav-page-web-services-in-c.aspx
 If you just want to assign a field through reflection you would do:PropertyInfo name = typeof(Customer).GetProperty("Name"); name.SetValue(customer, "new name", null);
 I use that in a number of places - although the above code is just written from the top of my head, so there could be spelling mistakes.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,
 Really it's a nice blog which you have posted.
 Really it will be helpful to many. =D>
 Thanks.0
- 
            hi Ravi,
 If you did fields dynamicly in webservices. then can u help me to insert and update sales order dynamicaly using C#.net Reflection namespace. I am able to read sales orders but not able to insert and update. i am not able to setvalue of propertyinfo filed and pass that property filed to insert method or update method or the web service
 if you have any code sample the kindly relply to this post
 :?
 Thanks and Regard
 Raju0
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
- 322 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




