toto1999
toto1999

Reputation: 213

Make field mandatory in import

I have one mandatory field in my entity X, but while importing data, I can create records even if I dont give that mandatory field a value, which is not good. How could I make that field mandatory even while importing?

Thanks in advance,

Upvotes: 3

Views: 1051

Answers (4)

Business rules with scope of "Entity" is the simplest no code solution to enforce this scenario.

For example, bulk data import, workflows, plugins, API/SDK calls would bypass the CRM forms and therefore would also bypass any JavaScript or form Business Rule validations you might have configured. These type of server-side validation had typically required plugins or synchronous workflows.

Luckily, business rules now have a new scope “Entity” which applies at the server level instead of the form level. What this means is that these business rules, just like plugins and sync workflows, will execute even if you are not using a CRM form in your transaction because they happen on the platform (server side) instead of the form (browser/client side).

Link to learn more: https://community.dynamics.com/crm/b/gonzaloruiz/archive/2016/08/15/business-rules-vs-sync-workflows-in-crm

Upvotes: 1

Sinepitis
Sinepitis

Reputation: 21

You could create Pre Operation plugin which runs on Create ,if entity doesn't contain this field ,throw out an error.(EDIT:I haven't tried this out so I'm not 100% sure it'll work)

Or

You could create Post Operation plugin which runs on Create , if entity doesn't contain this field ,then delete target entity.

Upvotes: 2

James Wood
James Wood

Reputation: 17562

Most mandatory fields are only enforced on the user interface. There are a few exceptions on some system entities, e.g. contact - lastname, account - name, incident - name, to list a few.

You want to enforce mandatory fields at the platform level, e.g. after the user interface before it is entered into the database.

The easiest way to do this is the following:

  1. Add a synchronous workflow to your entity, after on create or on change of your field.
  2. Add a condition to the workflow, if your field contains no data then run the following step:
    • Stop workflow; canceled, with a message of your choosing.

This will result in the import failing when the field is not populated and the record would not be created or updated. If you were to test this within CRM this would result in an error dialog being shown to the user.

Upvotes: 4

Henrik H
Henrik H

Reputation: 5787

The requirement level of fields (e.g. Business Required) is not enforced when doing imports (it is mainly enforced through the UI).

You will have to ensure that the required fields are set in your source data before doing an import.

Upvotes: 1

Related Questions