Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Validation across different forms - using javascripts or the best approach

(0) ShareShare
ReportReport
Posted on by 50

Dear experts,

I have a question. I want to do validation across the forms using javascript or the best approach in dynamics. Business rules have limitation that it cannot be applied on muliple entities but only one entity. I am using javascript to do a proof of concept.


I need to validate if "Field1" on first form is equal to "Field2" on second form(entity), or the sum of Field 1 and Field2 is equal to Field 1 in second form(entity).

For example: I have created two custom entites using customisation - setting> entity area.  For example

Entity1:  Field1, Field2

Entity2:  Field1, Field2

Each entity has its own set of fields and forms related to it. I understand, through javascript, I can use Xrm.Page.getAttribute("Field1").getValue() to get value of 1 field inside the form, but it seems it is only valid for that particular form context of Entity 1.

What I need to achieve is validation applied across two forms or three forms i.e. on
Entity1->Field2 = Entity1->Field1+ Entity2->Field1. 


In other words, I need to validate if "Field1" on first form(entity) is equal to "Field 2" on second form(entity), OR the sum of form1-Field 1 and form2-Field2 is equal to form1-Field 2. Is it possible in dynamics.? 

How can I get the reference of other entity/form in one javascript? Can someone guide me in right direction,

Kind regards,

*This post is locked for comments

  • nazimzia Profile Picture
    50 on at
    RE: Validation across different forms - using javascripts or the best approach

    Thanks Mahendar, this make sense, as I need the reference of another forms so that I can check validation as per initial post. Yes, I am aware of the deprecation of XRM.Page api

    So, there is no other way I can get the reference of Another forms in a form?

  • nazimzia Profile Picture
    50 on at
    RE: Validation across different forms - using javascripts or the best approach

    Hi Ambar, I do not have relationship between the entity. Actually One main Form, which will have all the forms linked to it. But the individual entities/forms are not connect to each other, but to a parent entity. I need to apply the validation rules on a particular form1, which looks into form 2 fields etc.

    On the other hand one more question:

    I believe, this can be done on custom portal, where you can apply validation on all entities like any HTML page. Can you pour some note to it?

  • nazimzia Profile Picture
    50 on at
    RE: Validation across different forms - using javascripts or the best approach

    Hi Goutam,

    As I mentioned before, business rule can only be applied on one entity. The wording "all forms" on business rule is slightly confusing, as it only means, "all forms for that particular entity only".

    My scenario as I mentioned, On the form UI, i need to apply validation across different entities forms.

    Are you still saying, we can apply business rule across multiple entity.

    On the other hand one more question:

    Is it easily done on custom portal, where you can apply validation on all entities like any HTML page. Can you pour some note to it?

    Kind regards,

  • gupta.ambar2009@gmail.com Profile Picture
    797 on at
    RE: Validation across different forms - using javascripts or the best approach

    If you have the relation ship b/w the entity then you can retrieve it .steps

    1- Get the value of Lookup field

    2- With lookup value ,you write a function to retrieve information from related entity

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Validation across different forms - using javascripts or the best approach

    I would suggest go for business rules first as  there is multiple scope like  forms, all forms and entity and this is easiest way no code approach.

    If you set scope of business rules All Forms then you your rules will be applied for all forms no matter field exists or not. In case of JavaScript you must need to add the fields into forms.

    Using business rules scope "Entity" you can apply logic server side as well so use business  rules or no  code approach as much as possible.

    If your business logic is complex let's say you need to validate regex or some custom criteria with API go for JavaScript.

    You can only get current entity reference using Xrm method, however you can retrieve data from another entity using API.

    Hope this helps.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: Validation across different forms - using javascripts or the best approach

    Hi,

    Your assumption is correct using page context you can get current form field value, but you can use WebAPI call to query another entity, if there is relationship between these entity then you can use the GUID or you can query entity based on some specific condition to get field values from other entity and compare it. You can write your Web API request using github.com/.../CRMRESTBuilder tool

    Also Xrm.Page is depreciated and will be removed soon in major release, You can find more details here: docs.microsoft.com/.../important-changes-coming

    Let us know if you need more help.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans