Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Invalid XML exception

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);
}
}
}
}


  • oliver.rodrigues Profile Picture
    oliver.rodrigues 4,052 on at
    RE: Invalid XML exception

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

  • Suggested answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 User Group Leader on at
    RE: Invalid XML exception

    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.

  • Suggested answer
    Kipetcoff Profile Picture
    Kipetcoff 1,002 on at
    RE: Invalid XML exception

    Here is another problem place

    2019_2D00_10_2D00_16_5F00_20_2D00_28_2D00_38.png

  • Suggested answer
    Kipetcoff Profile Picture
    Kipetcoff 1,002 on at
    RE: Invalid XML exception

    Hi,

    Try to write condition without {}

  • RE: Invalid XML exception

    I am passing a value dynamically leadoriginid my value

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans