Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Field valiation

Posted on by 35

Hello,

I have a question regarding field validation. What is the best/easiest way to create a validation for the customer field in the agreement.

The customer entity has a new field "blocked" and choosing a blocked customer in the agreement should throw an exception.

I tried a jscript function but I am not sure how to fetch related customer record, or if it is possible? Or is the best way using an c# plugin?

Or is there an easier way?

Thanks

Dominik

*This post is locked for comments

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Field valiation

    Hi,

    You need to use Web API query to retrieve the record. Once the value is retrieved, check the value and display error accordingly. The easiest way to write Web API query is to use Rest Builder Tool-

    Refer this blog carldesouza.com/.../

    You can download the tool here- github.com/.../releases

    For further reference on using this in an actual scenario, refer below blog which retrieves the value and set it on a field. In your case, once the value is retrieved, you need to check the value and display alert.

    community.dynamics.com/.../get-lookup-value-from-other-entity-and-set-it-on-the-form-using-web-api-in-microsoft-dynamics-crm

    If you still can't figure out then create a new thread with your script and I (or someone else) can take a look and assist you further :)

    Hope this helps.

  • DominikG Profile Picture
    DominikG 35 on at
    RE: Field valiation

    Hello Ravi,

    as the customer wants to see all customers at all time, I built a workflow as you suggested. This works just fine.

    Out of curiosity do you have any idea how a jscript function could look like?

    I tried this approach and managed to get an error when changing the value of the field. Yet I have no idea how to fetch the related customer record.

    Thanks for your help!

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Field valiation

    Hi,

    The best option is to instead of validating, you create a view for unblock customers and use that view in the lookup field. This way there will be no record to select from.

    If you still want to display all records, then add the validation using real time workflow. For this, create a real time workflow and trigger it on create of agreement. Within the workflow check if the customer is blocked. If it is then stop the workflow as cancelled and display error message. This is the simple/ easy way to add the validation.

    If you want to trigger the validation on select the account then you will have to write javascript, retrieve the details of the selected account and then check if it is blocked if yes then display error. To me writing this is unnessary effort as you have the above to easy options.

    I would not suggest plugin s for this requirement as it requires coding (the same reason as javascript)

    Hope this helps.

  • Suggested answer
    Priyesh Profile Picture
    Priyesh 7,392 User Group Leader on at
    RE: Field valiation

    Hi,

    Yes, plugin would be the best approach going forward because Real-Time workflow can't run before the creation of the record.

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans