Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Server Side Code/ C# - getting field values

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I am new to D365 online. I have built a couple of basic solutions with out of the box features that just takes and stores information. I want to take the next step of taking that user input and manipulating it on the server side after the user submits/saves that data. 

I already know that i have to create a .dll in visual studios, make reference to the D365 sdk lib, and the format of the dll (ex. the class, IPlugin, and execute function).

My question is:

1. When a user saves a record, how do i read the information from the entity form submitted - for example, a string/value in a textbox from a entity form.  Also, if that value was a normal text file with a string in it, how do i get that information?

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Server Side Code/ C# - getting field values

    Hi Merc

    You can write plugin with "Create" message. Below is the code

              IOrganizationService service = localContext.OrganizationService;

               IPluginExecutionContext context = localContext.PluginExecutionContext;

               if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

               {

                   Entity entity = (Entity)context.InputParameters["Target"]; // read the information from the entity

                   if (entity.Attributes.Contains("emailaddress1") && entity.Attributes["emailaddress1"] != null)

                   {

                       string emailAddress = entity.Attributes["emailaddress1"].ToString(); // a string/value in a textbox from a entity

                   }

               }

    Hope it helps.

    Thanks,

    Ridhima Behl

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Server Side Code/ C# - getting field values

    You are right, i want to do some type of processing when the information is submitted. The coding needs to be on the server side bc the amount of work that will be done will be heavy.

    Just for clarification - when you use the word "plugin", are you referring to server side code? how does Microsoft define "plugin"?

    Another question:

    is the MS site : docs.microsoft.com/.../mt676547(v%3dcrm.8) , the site i need to use to refer to information like the one you provided (ex. Entity entity = context.InputParameters["Target"];) ? or, is there another site?

  • Verified answer
    Priyesh Profile Picture
    Priyesh 7,396 User Group Leader on at
    RE: Server Side Code/ C# - getting field values

    Hi merc718,

    Though I assume you want to do some processing on a field when it is submitted. You can write a plugin or even a JS code on the form onSave.

    But since I'm not aware how much of plugin/JS for D365 experience you have, I'll suggest the following -

    You can read the JS code - as Xrm.Page.getAttribute("fieldname").getValue(); in JS code that you can put onSave on the Form where user is entering data.

    OR

    You can read the field in Plugin code as

    Entity entity = context.InputParameters["Target"];

    String name = entity.getAttributeValue<String>("fieldname");

    and then do operations on the name in C#.

    Let me know if you have even more particular question depending on whether you are trying to do this in JS or in Plugin and I can suggest in a better way.

    Apart from this, you can even check out how Calculated Fields and Business Rules work. Maybe that'll also help you instead of code if your business logic is straight forward.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans