Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Field Entry

Posted on by Microsoft Employee

Hi Community,

in one table (PriceTable) I have the fields "VehicleTyp" & "VehicleCategorie" .

Depending on the two fields "VehicleTyp" & "VehicleCategorie" and on their entries... I want to say that for each "VehicleTyp" (Car & Truck) it is for both only once possible to have the VehicleCategorie "not specified".

How is that possible via Code? &  what is the best practise of handling a Situation like that ?  

Thanks in advance.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Field Entry

       if (this.vehicletyp == 1 && this.VehicleCategorie == 1)

       {

           select VehicleTyp, VehicleCategorie from priceTable

               where   priceTable.VehicleTyp == this.VehicleTyp && priceTable.VehicleCategorie == this.VehicleCategorie;

               if (priceTable.VehicleTyp == 1 && priceTable.VehicleCategorie == 1)

               {

                   ret = checkFailed("Can't insert");  

               }

               else

               {

                   priceTable.VehicleTyp       = this.VehicleTyp;

                   priceTable.VehicleCategorie = this.VehicleCategorie;

                   ret = true;

               }

       }

       if (this.VehicleTyp == 2 && this.VehicleCategorie == 1)

       {

           select VehicleTyp, VehicleCategorie from priceTable

               where priceTable.VehicleTyp == this.VehicleTyp && priceTable.VehicleCategorie == this.VehicleCategorie;

           if (priceTable.VehicleTyp == 2 && priceTable.VehicleCategorie == 1)

           {

               ret = checkFailed("Can't insert");  

           }

           else

           {

                   priceTable.VehicleTyp       = this.VehicleTyp;

                   priceTable.VehicleCategorie = this.VehicleCategorie;

                   ret = true;

           }

       }

    it works so far.

    Only Problem is that, when I click on the same record after I saved it, and want to save it again... it says "Can't insert"

    Which I can understand... but are there any recommendations that You can give me to solve it ?

    And do you have any other tips ?

    Like do I Need a try catch Statement, Exception handling etc ??

    Thanks in advance.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Field Entry

    It worked. Thanks a lot.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Field Entry

    I will do that.

    Thanks.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Field Entry

    How about going into the validateWrite() of my Price Table ?

    Saying that it is only allowed for VehicleTypes "Car" and "Truck" to have a VehicleCategorie "NotSpecified" (0) only once in the Table ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Field Entry

    Yeah but that wouldn't be perfect, because You could have many vehicletypes which can have for example "midrange" as vehicleCategorie.

    Like

    Car | midrange | 4er | 150

    Car | midrange | c-class | 175

    this should be possible.

    Only Thing which should not be possible is that for one ´vehicleTyp there be twice "not specified" as categorie.

  • Mark Prouty Profile Picture
    Mark Prouty 1,310 on at
    RE: Field Entry

    Seems like you want to create a primary index using both fields. This would mean no duplicates for any VehicleType and VehicleCategory pair.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Field Entry

    Hi Sukrut,

    I put in a Screenshot.

    Do You see my first record and third ? (Highlighted)

    I already (3rd Record) have "Car" as VehicleTyp and "Not specified" as Categorie.

    One more record with the exact same entries for both fields, should not be possible.

    I want to mention that both fields are BaseEnums.

    4657.ForCommunity2.PNG

    Thanks in advance

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans