1

I've been looking through the net but can't find a proper answer...

I wrote a plugin in C# and when a condition is met, I would like to set a field readonly...

Thanks in advance !

MademoiselleLenore
  • 569
  • 1
  • 10
  • 25
  • Take a look at the two links one deals with Bindings and the other is an example of how you can do this... http://msdn.microsoft.com/en-us/library/system.reflection.bindingflags.aspx |http://stackoverflow.com/questions/934930/can-i-change-a-private-readonly-field-in-c-sharp-using-reflection – MethodMan Feb 14 '12 at 15:04
  • Read only at the server level, or read only at the client level? – Peter Majeed Feb 14 '12 at 19:56

1 Answers1

6

I think the problem you are running into is that you cant modify a field's enabled/disabled from the plugin.

You can, however, access the fields from javascript:

Xrm.Page.getControl('yourfieldname').setDisabled(true);

Here is info on how to setup the javascript for your forms: microsoft's form programming reference

BenPatterson1
  • 1,482
  • 12
  • 15
  • 4
    +1 for the javascript code, but have you checked out the `AttributeMetadata.IsValidForFilter` property? I can only imagine this can be accessed via a plugin. http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.metadata.attributemetadata.isvalidforupdate.aspx – Peter Majeed Feb 14 '12 at 21:44
  • +1 Peter, this is a good point, I've never knew that's applicable before. – Anwar Feb 15 '12 at 10:46
  • @PeterMajeed I didn't consider those properties, good idea. If the OP wants to commit changes to the entity itself that makes sense, if she wants a temporary change on the form she's stuck with javascript. – BenPatterson1 Feb 15 '12 at 16:43
  • Thank you guys ! I was a bit reluctant to use javascript but it did the job very well ! – MademoiselleLenore Feb 20 '12 at 17:39