Skip to main content

Posts

Showing posts with the label plugin

D365 Error converting attribute value to Property

 You are getting this error into your plugin  Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference' Your crud operation Entity field has a Lookup field relationship and it is expecting EntityReference. EntityReference conactEntityReference = new EntityReference { Id = newContactEntity.Id, LogicalName = Contact.EntityLogicalName }; localContext.OrganizationService.Update(new Entity(proevt_eventregistration.EntityLogicalName, inputEventseriesEntity.Id) { ["proevt_contactid"] = conactEntityReference });  

D365 call another action from plugin

 If we want to call another plugin or action from plugin we can use this approach. // Call std Copy action into plugin OrganizationRequest request = new OrganizationRequest("std_Copystd"); request["Target"] = stdEntityReference; OrganizationResponse response = localContext.OrganizationService.Execute(request); string clonestdresultresult = (string)response.Results["Result"]; string ClonestdId = (string)response.Results["CloneId"];

D365 update entity without retrive entity into plugin

 we can update any entity record without retrieving  String stdattendeeFetchXML = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='std_stdattendee' > <attribute name='std_contactid' /> <attribute name='std_attendeecategory' /> <attribute name='std_attendeeroleid' /> <attribute name='std_name' /> <filter type='and' > <condition attribute='std_stdid' operator='eq' value='{ClonestdId}' /> <condition attribute='statecode' operator='eq' value='0' /> ...

D365 plugin retrive entity data

  Retrieve Entity record data into plugin var inputcontract = (localContext.InputParameters["Target"] as Entity).ToEntity<student_contract>(); // retrive entity data Account accountEntity = localContext.OrganizationService.Retrieve( Account.EntityLogicalName, inputcontract.student_Account.Id, new ColumnSet(new String[] { "student_eventseriesid" })).ToEntity<Account>(); // You can also set the value without entity context ["student_eventseriesid"] = accountEntity.GetAttributeValue<EntityReference>("student_eventseriesid")

D365 FetchXML query into plugin

 Generate the xml query using xrmtoolbox and try with this code sample. String eventsessionFetchXML = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='baseevt_eventsession' > <attribute name='baseevt_eventid' /> <attribute name='baseevt_sessionenddatetime' /> <attribute name='baseevt_sessionstartdatetime' /> <attribute name='baseevt_name' /> <attribute name='baseevt_description' /> <filter> <condition attribute='baseevt_eventid' operator='eq' value='{inputEntity.Id.ToString()}' /> </filter> </entity> </fetch>"; var eventSessionresult =...