Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

to trigger the error if second record is checked.

(0) ShareShare
ReportReport
Posted on by 1,457
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
  • Suggested answer
    Deepak Agarwal Profile Picture
    Deepak Agarwal 8,564 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. 
  • Layan Jwei Profile Picture
    Layan Jwei 7,266 Super User 2024 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
    Layan Jwei Profile Picture
    Layan Jwei 7,266 Super User 2024 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
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 10,694 Super User 2024 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
    Martin Dráb Profile Picture
    Martin Dráb 230,466 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(...);
        }
    }
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 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
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 10,694 Super User 2024 Season 2 on at
    to trigger the error if second record is checked.
     
    You must use the validateWrite method.
     
    Best regards,
    Mohamed Amine MAHMOUDI

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans