Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

I am getting query builder error

Posted on by Microsoft Employee

this is the error i am getting 

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: ContactDetail:
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
<ErrorCode>-2147217150</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
<Message>Contact</Message>
<Timestamp>2016-11-21T10:39:22.6126423Z</Timestamp>
<ExceptionSource i:nil="true" />
<InnerFault i:nil="true" />
<OriginalException i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>

This is my code 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;

namespace images
{
public class plugin1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

IOrganizationService service = (IOrganizationService)servicefactory.CreateOrganizationService(context.UserId);

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

Entity Contact = new Entity("contact");

Contact.Attributes["firstname"] = Account.Attributes["name"];

Guid contactid = service.Create(Contact);

Account.Attributes["primarycontactid"] = new EntityReference("Contact", contactid);

}
}
}
}

*This post is locked for comments

  • Suggested answer
    Goutham A Profile Picture
    Goutham A on at
    RE: I am getting query builder error

    I have created a contact with only last name via sdk(but not on creation of account)

    Can you once make the first name field blank and try. Also please debug and see if  Account.Attributes["name"] is returning value or not

    Entity Account = (Entity)context.InputParameters["Target"];

    Entity Contact = new Entity("contact");

    Contact.Attributes["firstname"] = Account.Attributes["name"];

    Contact.Attributes["lastname"] = Account.Attributes["name"];

    Guid contactid = service.Create(Contact);

    Account.Attributes["primarycontactid"] = new EntityReference("Contact", contactid);

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I am getting query builder error

    i am getting same error, i need some clarification about that , when i am creating account we will give only name , but for contact we need  firstname and lastname, how my code will make concatenate both, can anyone help me  

  • Suggested answer
    Goutham A Profile Picture
    Goutham A on at
    RE: I am getting query builder error

    Hi avinay88,

     

    For contact, last name is mandatory field. Please rewrite your logic with lastname instead of first name

     

    Entity Account = (Entity)context.InputParameters["Target"];

    Entity Contact = new Entity("contact");

    Contact.Attributes["lastname"] = Account.Attributes["name"];

    Guid contactid = service.Create(Contact);

    Account.Attributes["primarycontactid"] = new EntityReference("Contact", contactid);

    Thanks 

    Goutham

    <<Please mark my answer as verified if it solves your query>>

     

  • Mridula Profile Picture
    Mridula 275 on at
    RE: I am getting query builder error

    Did you try debugging it?

    You can use profiler to debug the code.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I am getting query builder error

    still i didnt found any answer

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I am getting query builder error

    their is no workflows or business rules

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: I am getting query builder error

    I'm afraid this doesn't answer my question so I will reask - do you have any real-time workflows or business-rules that are used for validation of creation of contacts?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I am getting query builder error

    i just created trail version, and  i written my first plugin

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: I am getting query builder error

    Do you have any real-time workflows or business-rules that are used for validation of creation of contact?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I am getting query builder error

    yes

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans