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 Records in CRM using a standalone web application?

(0) ShareShare
ReportReport
Posted on by

Hi All,

         I need to create case records on CRM from a webapplication. I have already one web application in asp.net which is used by the users., My requirement is like i will add a form in that existing web application which will take the request data from users. Once they submit the form i have to create a new case record in my CRM 2016(onpremise). How to do this. Please share an example if you have.

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Joe Gill Profile Picture
    on at

    Hi,

    Probably the simplest approach would be do write some code in your ASP.NET app to create the case record similar to the sample https://msdn.microsoft.com/en-us/library/gg328416.aspx

    The alternatives would be either call the CRM WebAPI from Javascript https://community.dynamics.com/crm/b/scaleablesolutionsblog/archive/2016/01/18/web-api-authentication-from-javascript

    or write you own custom Web Api to create the case and call this Web API from your ASP.NET app

    hth

    Joe

  • Verified answer
    Faizal Profile Picture
    545 on at

    Hi,

    Just high level:

    • Create ASP.Net program and connect to CRM via SDK & Connection string.
    • On page load; necessary aspx form validation.
    • On button send/create/update:
      • Store user entry from aspx to CRM case attribute.
      • Prepare necessary validation in the code to create/update case record.

    example:

    //################################################################################

    protected void Page_Load(object sender, EventArgs e)
    {
    if(fn_ConnectToMicrosoftCRMOnline())
    {
    txtFirstName.Focus();
    if (!Page.IsPostBack)
    {
    DropDownDataBind();
    }
    }
    }

    //###########################################################################################################

    private bool fn_ConnectToMicrosoftCRMOnline()
    {
    bool permission = false;
    if (Convert.ToBoolean(ConfigurationManager.AppSettings["OnlineCRM"].ToString()) == false)
    permission = CommonClass.Connect_CRMWindowsAuth();
    else
    permission = CommonClass.Connect_CRM();

    lvObj_CRMServiceProxy = CommonClass.Proxy;
    return permission;
    }

    //###########################################################################################################

    private void DropDownDataBind()
    {
    ddlGender.DataSource = CommonClass.BindOptionSet("incident", "new_gender");
    ddlGender.DataBind();

    }

    //################################################################################

    protected void Button1_Click(object sender, EventArgs e)
    {
    Page.Validate();
    if (Page.IsValid)
    {

    Mandatory = true;

    Entity Incident= new Entity("incident");

    //Text field.###########
    if (txtFirstName.Text != string.Empty)
    {
    Volunteer.Attributes["new_name"] = txtFirstName.Text;
    lbFirstName.Visible = false;
    }
    else
    {
    lbFirstName.Visible = true;
    lbFirstName.ForeColor = Color.Red;
    lbFirstName.Text = "Missing Mandatory Field";
    Mandatory = false;
    }

    //DropDown.###########
    if (Convert.ToInt32(ddlGender.SelectedIndex) > 0)
    {
    int test = Convert.ToInt32(ddlGender.SelectedValue);
    Volunteer.Attributes["new_gender"] = new OptionSetValue(Convert.ToInt32(ddlGender.SelectedValue));
    }

    // Create Incident based on validation.###########

    if ((CaptchaStatus) && (Mandatory))
    {
    lvObj_CRMServiceProxy.Create(incident).ToString();
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('Application submitted successfully.');", true);
    ClearControls(this.Page);
    }

    //################################################################################

  • Community Member Profile Picture
    on at

    Dear Faisal & Joe Gill ,

       I created a webform and added the code as you suggested. My CRM is CRM 2106 onpremises. The issue now is the proxyservice does not get authenticated. It says some certification issue.

    crmw2016/.../Discovery.svc

    even the discovery service url is not working in the browser. It shows not secured. I am using my active directory credentials to connect the service and create record. Can you suggest what are the changes i have to do in active directory to make it out?

  • Verified answer
    Joe Gill Profile Picture
    on at

    You should not need to touch AD.

    Are you running you asp.net app on premise? Can you connect to CRM using the same credentials?

  • Community Member Profile Picture
    on at

    unsafe.png

  • Community Member Profile Picture
    on at

    Yes i am connecting CRM using same credentials. And I am running the asp.net application from the CRM server mechine only.

    The dicovery service throws this exception "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

  • Verified answer
    Community Member Profile Picture
    on at

    Please add the below line in your code just before the connecting to CRM:

    ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };    

  • Community Member Profile Picture
    on at

    Now i am getting this error

    An exception of type 'System.ServiceModel.Security.SecurityNegotiationException' occurred in Microsoft.Xrm.Sdk.dll but was not handled in user code Additional information: The caller was not authenticated by the service.

  • Verified answer
    Community Member Profile Picture
    on at
  • Verified answer
    Faizal Profile Picture
    545 on at

    Hi Nidhincee,

    If you are using window authentication, u can follow this for connection.

    public static bool Connect_CRMWindowsAuth()
    {
    ClientCredentials Credentials = new ClientCredentials();

    Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

    Uri OrganizationUri = new Uri(ConfigurationManager.AppSettings["CRMURL"].ToString());

    Uri HomeRealmUri = null;

    Proxy = new OrganizationServiceProxy(OrganizationUri, null, Credentials, null);

    Proxy.EnableProxyTypes();

    Guid currentUserId = Guid.Empty;
    currentUserId = GetUserId(Proxy);
    Proxy.CallerId = currentUserId;

    }

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