web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Invalid XML exception

(0) ShareShare
ReportReport
Posted on by 15

I am getting invalid XML error can anyone help me

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Query;
using System.Web.UI.WebControls;
using Microsoft.Xrm.Sdk.WebServiceClient;


namespace postoperationonaccount
{
public class postoperation : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);

try
{
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];

if (entity.LogicalName == "account")
{
var leadoriginid = entity.GetAttributeValue<EntityReference>("originatingleadid").Id;
Console.WriteLine(leadoriginid);

if (leadoriginid != null)
{
StringBuilder fetch = new StringBuilder();
fetch.Append("<fetch version='1.0' output-format='xml - platform' mapping='logical' distinct='true'>");
fetch.Append(" <entity name='competitor'>");
fetch.Append("<attribute name='name' />");
fetch.Append("<attribute name='websiteurl' />");
fetch.Append("<attribute name='competitorid' />");
fetch.Append("<order attribute='name' descending='false' />");
fetch.Append("<link-entity name='leadcompetitors' from='competitorid' to='competitorid' visible='false' intersect='true'>");
fetch.Append("<link-entity name='lead' from='leadid' to='leadid' alias='ag'>");
fetch.Append("<filter type='and'>");
fetch.Append("<condition attribute='leadid' operator='eq' value='{"+leadoriginid.ToString()+"}' />");
fetch.Append("</ filter>");
fetch.Append("</link-entity>");
fetch.Append("</link-entity>");
fetch.Append("</entity>");
fetch.Append("</fetch>");

// var query=string.Format(fetchxml, leadoriginid.ToString());
EntityCollection competitorresult = service.RetrieveMultiple(new FetchExpression(fetch.ToString()));
Console.WriteLine(competitorresult);
var relatedentities = new EntityReferenceCollection();
foreach (var e in competitorresult.Entities)
{
relatedentities.Add(new EntityReference("competitor", e.Id));

}
var relationship = new Relationship("sb_competitor_account");
Guid entityid = entity.Id;
service.Associate("account", entityid, relationship, relatedentities);
}
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}


I have the same question (0)
  • Preetham Holenarasipuradeveraju Profile Picture
    15 on at

    I am passing a value dynamically leadoriginid my value

  • Suggested answer
    Kipetcoff Profile Picture
    1,037 on at

    Hi,

    Try to write condition without {}

  • Suggested answer
    Kipetcoff Profile Picture
    1,037 on at

    Here is another problem place

    2019_2D00_10_2D00_16_5F00_20_2D00_28_2D00_38.png

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    Hi Preetham!

    @Andrey is right. You don't have to pass the dynamic values with curly braces. Also, you have extra space as @Andrey shown in the screenshot.

  • oliver.rodrigues Profile Picture
    4,052 on at

    please review the tags used in the thread, tagging all of options won't get your answer quicker

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Nagaraju_Matta Profile Picture

Nagaraju_Matta 123

#2
Hamza H Profile Picture

Hamza H 96 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 66 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans