Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to pass a value on a textbox field from a form to a C# plugin using Web Api

Posted on by 575

Hi:

I am using an onpremise version of CRM 2016.

I have been reading a lot of the tutorials on how to use the Web Api but I have not found any resources that show me how to pass a value on a textbox field from a form (client side) to a C# plugin using Web Api that will update by adding or updating records to the SQL database.

private JObject contact1 = new JObject()

contact1.Add("firstname", "Peter");

contact1.Add("lastname", "Campbell");

HttpRequestMessage createRequest1 = new HttpRequestMessage(HttpMethod.Post, getVersionedWebAPIPath() + "contacts");

createRequest1.Content = new StringContent(contact1.ToString(),Encoding.UTF8, "application/json");

HttpResponseMessage createResponse1 = await httpClient.SendAsync(createRequest1);

From the above you will see that I added "Peter" and "Campbell" to the firstname and lastname fields. How would this be done if firstname and lastname were instead form textbox fields?

Steve

*This post is locked for comments

  • SivaR Profile Picture
    SivaR 459 on at
    RE: How to pass a value on a textbox field from a form to a C# plugin using Web Api

    Hi

    i am using Dynamics 365 online version - portal form. how do i get the text field value from the Portal form submit into Plugin code?

  • SteveWhyte Profile Picture
    SteveWhyte 575 on at
    RE: How to pass a value on a textbox field from a form to a C# plugin using Web Api

    AHHH!!!!! Bingo.......I thought so but I wasn't sure......

    Thanks Mohd, Thanks Nadeeja.....

    Appreciate the feedback. I haven't tested it as yet but it makes a lot of sense

    Steve

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to pass a value on a textbox field from a form to a C# plugin using Web Api

    If you are running this code on a form then you can use is like this:

    var firstName= Xrm.Page.getAttribute("firstname").getValue() ;

    var lastName= Xrm.Page.getAttribute("lastname").getValue() ;

    contact1.Add("firstname", firstName);

    contact1.Add("lastname", lastName);

  • SteveWhyte Profile Picture
    SteveWhyte 575 on at
    RE: How to pass a value on a textbox field from a form to a C# plugin using Web Api

    Thanks for your response Nadeeja.

    Although I indicated I am using CRM 2016, I actually using WebAPI to retrieve my data. So far the Microsoft samples that I have been finding use "hard coded" data to save to the SQL database. I would like to see a sample that uses the field values on a CRM form rather than using "hard code" values to update a database. Can you help me on this?

    Steve

  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    Nadeeja Bomiriya 6,804 on at
    RE: How to pass a value on a textbox field from a form to a C# plugin using Web Api

    Hi SteveWhyte,

    It is not quite clear what you are trying to do.  With regards to Dynamics 365 (CRM) plugins, regardless of how data comes into Dynamics 365 (CRM), the plugins will trigger.  Register your plugin on pre-operation of create or update and look at the data inside context.InputParameters["Target"];.

    msdn.microsoft.com/.../gg309673.aspx

    If you are trying to access the Textbox value from code behind of an ASP.NET Web Application and you are using HTML input element.

    <input type="text" name="mytextbox" />

    Then, on postback, use below to get the value of textbox.

    string value = Request.Form["mytextbox"];

    If you are using MVC or Forms then you need to use appropriate methods to access the 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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans