Search code examples
dynamics-crm-2015

Setting a fields default value to the result of some calculation


I have 2 entities, let's call them Parent and Child, with a 1:n relationship, where one Parent can have 0-n Child.

The Parent has two fields, Parent.Number and Parent.Name. When creating the Child via the plus button in a subgrid of Parent, the Child.Name should be preset to:

Child of Parent.Name (Parent.Number)

I've tried lots of different approaches wich all led to dead Ends. Some of them were:

  • Calculating via BusinessRules
  • Calculated Field on Child in combination with BusinessRules
  • Calculated Field on Parent, transferring the precalculated Text to the Child entity by Mapping.
  • Calculated Field on Parent, using a BusinessRule to set it's value as the default value of Child.Name
  • Using a workflow for Child.OnAfterCreate (works, need it in the OnFormLoad, though)

(For brevity I will not go into details of why each approach did not work, but will elaborate on request.)

Is there any way to achieve this without the use of Client side Scripting that I am not aware of?


Solution

  • Without using JavaScript (which is a solution) I can only suggest the following approaches (of which you can use some or all) which are all compromises really:

    • Change your requirement to make the name as shown below. A business rule on the child can then be used to populate this information. It can access the name but not any other field, i.e. number.

    Child of Parent.Name

    • Use a quick view form to show the parent details on the child. This allows users to see the data even if the name is not set correctly.

    • Use one of the above, and the workflow. So the correct value is still finally set and you provide the user with as much information as possible until that point.

    • Remove the name field from the child form body. Use a workflow to set the value, when the form is saved. CRM displays names at the top of the form so it will appear as soon as they save but they wont see an empty field before that.

    • Change the name of the parent record to as shown below, you can then use that in business rules on the child.

    Parent.Name (Parent.Number)