Hello,
I am new to CRM C# development. I have the following piece of code:
internal static Entity CreateContractLine(Prod productstar, decimal quantity, Guid userId, Guid contractId, IOrganizationService crmService, Guid parentContractLine, bool isRelated = false)
{
Entity crmdetail = new Entity(Constants.EntityName.ContractLine); //Constants is the name of a common file and it is referring to the logical name of an entity called ContractLine.
crmdetail[Constants.Attributes.ContractLine.ProductId] = new EntityReference(Constants.EntityName.Product, productstar.id); //left part is the schema name of an attribute called ProductId.
the ProductId attribute in the entity crmdetail is a single line of text field in CRM. I need to check if this attribute contains the word "Cheese Pizza" as part of its string. How do I do that?
*This post is locked for comments
Thank you so much ! That helped!
Then you need to query it from the server.
Might do it this way:
var product = service.Retrieve(Constants.EntityName.Product, productstar.id, new ColumnSet("name"));//Make sure it's actually called "name"on the product entity
var productName = (string)product["name"];
Hi Alex,
You're right. It is setting to an entity reference. I need to read this attribute value and check as part of its string contains the phrase "Cheese Pizza"
Hi,
in your code, you seem to be setting that attribute, not reading from it.. Yet you are setting it to an entity reference.. Could you clarify what/where you need to do?
As a side not.. when you have an entity reference, sometimes you will have "Name" in the entity reference. Sometimes, it won't be there (depends how that entity reference ended up there). If it's not there, you need to retrieve that entity from CRM (service.Retrieve), include "name" attribute into the list of columns, and, then, you'll have the name
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156