I have a requirement to add fields onto a form based on data from another set of entities. Is this possible using an event script or does it require a plugin?
-
Do you mean add fields that don't exist for the entity, or to update values of fields that don't exist, or to default fields on the entity, based on another entity? – Daryl Mar 07 '13 at 20:59
-
I want to add fields to a form based on existing attributes in a different entity – Gary Mar 07 '13 at 21:08
-
See edit, especially suggested follow-up question *4c*. – Konrad Viltersten Mar 09 '13 at 09:40
-
You can't dynamically add fields to a form, you can only hide/show the fields already defined for the entity as attributes. You could dynamically add attributes to the entity, but I would advise against it. That would be nightmarish to maintain, e.g. if one account has 5 products, and other has 10 would you create 10 new fields or 15? If you have 1000 products do you have 1000 attributes? (there is a limit on the number you can have). This doesn't sound like a sane design. If thats what you really want to do then I would rethink, if its not, please be more specific in your question. – James Wood Mar 09 '13 at 10:58
1 Answers
Given that I understand your assignment correctly, it can be done using JavaScript as well as a plugin. There is a significant difference that you need to take into consideration.
Is the change to the other entities to be made only when an actual user loads a form? If so, JS is the right way.
Or perhaps you need to ensure that those values are written even if a console client or system process retrieves the value of the primary entity? In that case, C# is your only option.
EDIT:
Simply accessing the values from any entity in the onload event can be done using a call to oData. I believe someone else asked a similar question recently. The basic format will look like this.
http://Server:Port/Organization
/XrmServices/2011/OrganizationData.svc
/TheEntityLogicalNameOfYoursSet()?$filter=FieldName eq 'ValueOfIt'
Some extra remarks.
If you're targeting on-line installation, the syntax will differ, of course, because the Schema-Server-Port-Organization are provided in a different pattern (https, orgName.crm4.something.something.com etc.). You can look it up on Settings.
Perhaps it should go without saying and I'm sure you realize it but for completeness' sake, TheEntityLogicalNameOfYours needs to be substituted for the actual name (unless that is your actual name, in which case I'll be worried, haha).
If you're new to this whole oData thingy, keep asking. I got the impression that the info I'm giving you is appreciated but not really producing "aha!" experience for you. You might want to ask separate questions, though. Some examples right off the top of my head.
a. "How do I perform oData call in JavaScript?"
b. "How do I access the fetched data?"
c. "How do I add/remove/hide a field programmatically on a form?"
d. "How do I combine data from...?"

- 1
- 1

- 36,151
- 76
- 250
- 438
-
Thanks Konrad. When I open the account form, I want to look at the products that they purchased and add a checkbox to the form for those products. So, I don't need to worry in that case about the console or system processes. I'm not making any changes to any entity. Is there a good example showing how to do that? Thanks again. – Gary Mar 08 '13 at 21:52
-
See my edit. It got clearer now but I was still a bit uncertain. We'll get you there, though, no worries. :) – Konrad Viltersten Mar 09 '13 at 09:20
-
Thanks again. I wish there was better documentation on all of the programming techniques for CRM. I understand the SDK has documentation but it is very hard (at least for me) to piece everything you need to know together online a bit at a time. I'm new to all of this, so yes it is very appreciated and I think your suggestion is a good one. I will break it up into multiple questions now that I know which questions to ask. – Gary Mar 11 '13 at 15:43
-
@Gary if you look in the SDK, there should be a JS REST file, look for the RetrieveMultiple call. It will simplify the OData calls and return them in JSON format. Best of all, it will alleviate the need to understand the underlying calls (unless you want to know them). – Mike_Matthews_II Mar 11 '13 at 19:13
-
@Gary You're not alone. You're far from alone. In fact, I'm nagging on my boss to write a book on CRM with focus on programming. He'd do that but only if his wife lets him (time consumption consideration). Mail him, would you? The more pressure he gets, the more likely he's to cave in and get busy. (And no, I'm not writing alone. I need a co-writer. Interested?) – Konrad Viltersten Mar 12 '13 at 11:10