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)

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

(0) ShareShare
ReportReport
Posted on by 583

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

I have the same question (0)
  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    6,804 on at

    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.

  • SteveWhyte Profile Picture
    583 on at

    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

  • Verified answer
    Community Member Profile Picture
    on at

    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
    583 on at

    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

  • SivaR Profile Picture
    69 on at

    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?

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