Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Create contact from ASP.Net page

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

  • Stuie Profile Picture
    Stuie 255 on at
    RE: Create contact from ASP.Net page

    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

  • Stuie Profile Picture
    Stuie 255 on at
    RE: Create contact from ASP.Net page

    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

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Create contact from ASP.Net page

    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
    Stuie 255 on at
    RE: Create contact from ASP.Net page

    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. 

  • Stuie Profile Picture
    Stuie 255 on at
    RE: Create contact from ASP.Net page

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

  • Mohsin Ali Profile Picture
    Mohsin Ali 3,610 on at
    RE: Create contact from ASP.Net page

    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
    Stuie 255 on at
    RE: Create contact from ASP.Net page

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

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Create contact from ASP.Net page

    Hi,

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

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

  • Suggested answer
    sandeepstw Profile Picture
    sandeepstw 4,601 on at
    RE: Create contact from ASP.Net page

    Hi,

    Please refer this article

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

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