web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

to trigger the error if second record is checked.

(0) ShareShare
ReportReport
Posted on by 1,836
hi ,
Everyone ,
I am having one checkbox field on form which is table field yesno so i want only single record on the form to be checked it should trigger error , how can i get it done plz guide me on this ,below is my form 
thanks,
Regards,
Dinesh
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
    to trigger the error if second record is checked.
     
    You must use the validateWrite method.
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Dineshkarlekar Profile Picture
    1,836 on at
    to trigger the error if second record is checked.
    hi ,
    Thanks for reply ,
     
    I am having issue if i write the code on validate it will check for current record , do i have to use loop or any condition to compare it with previous checked record ,can you please help me on this .
     
    thanks ,
    Regards
    Dinesh
  • Suggested answer
    Martin Dráb Profile Picture
    237,640 Most Valuable Professional on at
    to trigger the error if second record is checked.
    Stop for a moment about what you want to achieve. Then you'll be able to answer questions like whether you need a loop for anything.
     
    You want to check if there is a record in database that has the checkbox ticked and it's not the current record. The way how you can query data is using a select statement. For example:
    if (this.Checked)
    {
        select firstOnly RecId from myTable
            where myTable.Checked
               && myTable.RecId != this.RecId;
    
        if (myTable.RecId)
        {
            ok = checkFailed(...);
        }
    }
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
    to trigger the error if second record is checked.
     
    try this :
        boolean validateWrite()
        {
    		boolean		ok;
    		MyTable		myTable;
    		
    		ok = super();
    		if(this.checked)
    		{
    			select myTable where myTable.checked == NoYes::Yes
    			&& myTable.RecId != this.RecId;
    			
    			if(myTable)
    			{
    				ok = checkFailed(strFmt("Erreur !"));
    			}
    		}
    		
    		return ok;
        }
    Best regards,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    to trigger the error if second record is checked.
    Hi Dinesh,

    Your explanation for the requirement is not very clear. If I understood correctly, only one record in the table can have Checked =yes?
     
    Would you like the error to appear when you directly tick the box and navigate to another field? In this case you can use the validateField method
    or if you would like the error to appear when you click save, then you can use validateWrite method

    And yes you need to check that current record recId  is not equal to the record where the checked field is yes. In order to know if there is more than one record with checked =yes

    Thanks,
    Layan Jweihan
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    to trigger the error if second record is checked.
    Hi,
     
    Is your question answered? If yes, then please verify the answers that helped.
  • Suggested answer
    Deepak Agarwal Profile Picture
    8,598 on at
    to trigger the error if second record is checked.
    Why not to use an ENUM for Purhcase type, by that way you will alwasys select just one value and you can avoid all other things. 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 758 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 607 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 402 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans