Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

How to create two buffer values for one table in x++ ?

Posted on by 45

Consider this below example.

pastedimage1621515030110v1.png

Condition 1: When user tries to enter same id and same name it must throw an error A. So, in 2nd line that data is not acceptable.

Condition 2 : When user tries to enter same id , same name, and same place then it must throw an error B. 3rd line data not acceptable.

I'm able to code condition 2 individually using validateWrite() Method, but not able to add condition 1 inside same validateMethod().

When I'm trying to create second buffer value for Table, it is throwing error as "Variable xyz not used"  

And when I tried with  job, it is throwing error as "Error executing code: (object) has no valid runable code in method 'Job1'.Stack trace"

Please explain how to resolve these errors.

Note:- It can be done via indexing but I want to throw customized error message. So, I'm coding.

Thanks in advance :-) 

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: How to create two buffer values for one table in x++ ?

    Hi Vaishnav,

    Why you do not use specific index in your table or data source?

  • ergun sahin Profile Picture
    ergun sahin 8,812 Super User on at
    RE: How to create two buffer values for one table in x++ ?

    Actually, I understood what you wanted to do, but I didn't understand why you could control the trio but not control the two. That's why I wanted to ask if you would like something else.

    I think you will need to share the code so we can fully understand the problem.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to create two buffer values for one table in x++ ?

    Hi Vaishnav,

    it would really help if we could see your code.

    But generally you can use select statements to find records based on any criteria that you like.

    So if you want to check if some record in the table already has the same three fields, just write a select statement to find a record with same values in those three fields.

    If you want another check for two fields, you need to run that check after the "three field check". This is because the "two field check" will catch both cases.

  • Vaishnav Profile Picture
    Vaishnav 45 on at
    RE: How to create two buffer values for one table in x++ ?

    pastedimage1621590367596v1.png

    The Place value can be empty or filled. So, it should trigger two different errors for 2nd and 3rd lines respectively.

    This is the requirement to trigger customized error messages.

  • ergun sahin Profile Picture
    ergun sahin 8,812 Super User on at
    RE: How to create two buffer values for one table in x++ ?

    I think the 2nd control is faulty. The fact that 3 fields are the same also means that the two fields are the same. No need for second control

  • Vaishnav Profile Picture
    Vaishnav 45 on at
    RE: How to create two buffer values for one table in x++ ?

    Sorry , that was a mistake.

    Please consider below screenshot

    pastedimage1621516670555v1.png

    Hope it is clear now.

    And yes in second line "Place" is empty. So , that is different .

    Both are two different conditions.

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to create two buffer values for one table in x++ ?

    Vaishnav wrote "It can be done via indexing but I want to throw customized error message. So, I'm coding."

    But, I also think that this doesn't make sense - users are already familiar with the standard error messages that unique index violations give across the system. Now they need to learn to understand different error messages in this one scenario.

    Not to forget all the time and money that's being spent working with this code. With proper unique index, the feature would already be done and Vaishnav could be providing value with next task.

  • Martin Dráb Profile Picture
    Martin Dráb 225,783 Super User on at
    RE: How to create two buffer values for one table in x++ ?

    I don't understand the second case. You said that it shouldn't accept "same id , same name, and same place", which is already covered by the first case. But your example doesn't match your description - ID (002) is unique there.

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to create two buffer values for one table in x++ ?

    I think there must be some issue in your code. Do you think you could share your code so that we would be able to see what might be wrong with it?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans