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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Create contact from ASP.Net page

(0) ShareShare
ReportReport
Posted on by 255

Hi

I want to create a contact in Dynamics 365 from a webpage but I'm getting a basic error which tells me nothing.
Exception rethrown at [0]

Please help.

 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
        Dim service As CrmServiceClient = New CrmServiceClient(ConfigurationManager.ConnectionStrings("CRM").ConnectionString)
        Dim contact As Entity = New Entity("contact")
        Dim lang As String = "7ed34d80-5755-e511-80e9-3863bb34ea78" ' us english
        Dim langGuid As Guid = New Guid(lang)


        contact("firstname") = "Stuie"
        contact("lastname") = "Green"
        contact("emailaddress1") = "stuapitest@xxx.com"
        contact("tri_sitelanguageid") = langGuid
        contact("tri_al_atpcampaign") = "test Form"
        contact("tri_al_country") = "USA"
        contact("tri_al_enquiry") = "testing"
        contact("new_testid") = langGuid

        Try
            service.Create(contact)
        Catch ex As Exception
            Response.Write(ex.Message)
            Response.End()
        End Try


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    sandeepstw Profile Picture
    4,601 on at

    Hi,

    Please refer this article

    community.dynamics.com/.../how-to-connect-to-crm-using-sdk

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    Instead of using Exception class, I will suggest you to catch OrganizationServiceFault which will give you error details

    msdn.microsoft.com/.../gg327884.aspx

  • Stuie Profile Picture
    255 on at

    Thanks for the reply but unfortunately it didn't help. Same error

  • Mohsin Ali Profile Picture
    3,634 on at

    it looks that tri_sitelanguageid and new_testid are lookup fields so you need to setup these fields values using following snippet:

    contact("tri_sitelanguageid") = new EntityReference(<EntityLogicalName>, langGuid)

    contact("new_testid") = new EntityReference(<EntityLogicalName>, langGuid)

  • Stuie Profile Picture
    255 on at

    THhanks Mahen. Do you have a vb.net example?

  • Stuie Profile Picture
    255 on at

    Hi all

    I got this to work OK and its now creating contacts fine BUT I have another plugin in CRM that updates a SQLdb when modified date changes. 

    It appears that when a new contact is created, this step message of Update triggers the plugin and causes the error.
    I think its probably trying to update a record that's not been created yet in SQLdb

    How can I see error details like i can when using profiling of the plugin.

    All i see on the webpage is 

    Unexpected exception from plug-in (Execute): ContactDataProcessing.GetContactDataPlugin: System.NullReferenceException: Object reference not set to an instance of an object. 

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    You can control update plugin using filtering attribute to only trigger your update plugin on change of specific fields, docs.microsoft.com/.../include-filtering-attributes-plugin-registration

    further if you want to debug your plugin you can check my post here: http://himbap.com/blog/?p=2469

  • Stuie Profile Picture
    255 on at

    Thanks Mahener. Id like to use filtering.

    I already have modifiedon as a filter but can I add logic to say only run the plugin if modifiedon != createdon

  • Stuie Profile Picture
    255 on at

    Also the debugging only seems to be for when I have a profile file to test against. I'm running an aspx page to call the plugin so don't have a profile

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans