Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

How to use the Entity class for creating Orders but also add the products on the order???!!!

$
0
0

Hi Everyone, I manage to create a program that can create an order using the link provided below.

While that is fine, the challenge comes from the new_ordernumber field in the Salesorder entity.

This gets automatically generated on the backend, and I'm not sure how I can reference that value to

be used to create a product via the salesorderdetail entity. I provided the code below, but I'm not sure

how to reference the new_ordernumber from the salesorder entity and use it to create a new record in the

salesorderdetail entity. Can someone please help? Thanks!

Reference: https://msdn.microsoft.com/en-in/library/gg309731.aspx

foreach (var r in orders) { _service = (IOrganizationService)_serviceProxy; // Instaniate an salesorder object. Entity salesorder = new Entity("salesorder"); // Set the required attributes. For salesorder, only the name is required. // See the Entity Metadata topic in the SDK documentatio to determine // which attributes must be set for each entity. salesorder["name"] = r.Name.ToString(); salesorder["new_ordernumber"] = // Create an salesorder record named "Test"; _orderId = _service.Create(salesorder); Console.Write("{0} {1} {2} created, ", salesorder.LogicalName, salesorder.Attributes["name"], salesorder.Attributes["new_ordernumber"]); // Create a column set to define which attributes should be retrieved. ColumnSet attributes = new ColumnSet(new string[] { "name", "ownerid" }); // Retrieve the salesorder and its name and ownerid attributes. salesorder = _service.Retrieve(salesorder.LogicalName, _orderId, attributes); Console.Write("retrieved, "); // Update the customer attribute. salesorder["new_promotioncode"] = "TEST CODE"; // Update the salesorder. _service.Update(salesorder); Console.WriteLine("and updated."); // Delete the salesorder. bool deleteRecords = true; if (promptForDelete) { Console.WriteLine("\nDo you want these entity records deleted? (y/n) [y]: "); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y") || answer == String.Empty); } if (deleteRecords) { _service.Delete("salesorder", _orderId); Console.WriteLine("Entity record(s) have been deleted."); } } } } // Catch any service fault exceptions that Microsoft Dynamics CRM throws. catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>) { // You can handle an exception here or pass it back to the calling method. throw; } } } }



Viewing all articles
Browse latest Browse all 1000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>