Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

Use the Entity class to create orders in CRM - please help!!!

$
0
0

Hi everyone, I'm very new to CRM C# development and need help. I was able to use the code provided in the reference link below to create a new Order (salesorder) in CRM. While that works, I am not able to get it to add a product to the same salesorder entity from this code. I believe the way the two entities relate by the ordernumber.  Can someone help me be able to add an existing product (lookup) to this new order?

Reference: msdn.microsoft.com/.../gg328416.aspx

Thank you!!

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 55831

Trending Articles



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