Skip to main content

Notifications

Microsoft Dynamics AX forum
Answered

How to know field have a value Exist in X++

Posted on by 115

While creating a New Vendor in AX in Account Payable module.then I enter Name , Search-name , Group  , then I press ctrl+S ,,then Record is saved in respective tables.

I need condition that , If record is saved then "How to know , I mean what is the X++ code for this""

client requirement is Denied saving record without enter Adresss tab wih adress details..

  • PK mishra Profile Picture
    PK mishra 115 on at
    RE: How to know field have a value Exist in X++

    Thank You So Much .You are great.

    Now Its Work...

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,150 on at
    RE: How to know field have a value Exist in X++

    Perhaps you can set isNewVendor variable in create method of the data source. But your code can never be bullet proof because vendor is always saved without address. 

    My suggestion: if vendor has no address, show a Box::YesNo asking if the user is sure that they want to close the form, when address is missing. This reminder would be shown for new and existing vendors which don't have address.

    You can not prevent users from creating vendors without address, so just remind them, that's the best you can do. Also, your code would be simple and the logic would be simple for the users to understand (instead of "why can I sometimes close the form without having address and sometimes not?").

    Would that work for you?

  • PK mishra Profile Picture
    PK mishra 115 on at
    RE: How to know field have a value Exist in X++

    I Did , what you have say , but its, did not working..

    Can i put the validation on VendTable.createddatetime field to achieve this result, if yes then whats the code ..?

    My current code is this..

    public boolean canClose()
    {
        boolean ret;
    
        LogisticsLocation LogisticsLocation;
        LogisticsPostalAddress LogisticsPostalAddress;
        DateTimeUtil DateTimeUtil;
     
     if (isNewVendor == true)
        {
    
        if(!DirPartyPostalAddressView && !VendTable)
        {
    
         ret = true;
        
        }
        if(DirPartyTable && VendTable && !DirPartyPostalAddressView)
        {
            ret = false;
            checkFailed("Please Go to the Adresses Tab & Enter Mandatory Adress for the Vendor");
         }
    
    
        if(DirPartyTable && VendTable && DirPartyPostalAddressView )
        {
            ret = super();
        }
        }
        if(isNewVendor == false)
        {
            ret = super();
        }
    
        return ret;
    
    
    }

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,150 on at
    RE: How to know field have a value Exist in X++

    First of all, please click "Use rich text formatting", then "Insert -> Code" when you share your code. It's much easier to read that way.

    So do you still expect to have vendors without addresses? I thought you don't want to have them.

    Anyway, I think you can solve it by adding new boolean variable "isNewVendor" in your form's classDeclaraion. Then, in active method of VendTable data source, put this line of code:

    iNewVendor = !vendTable.RecId;

    Now you can add new condition in your canClose method, depending if isNewVendor is true or false.

  • PK mishra Profile Picture
    PK mishra 115 on at
    RE: How to know field have a value Exist in X++

     if i am creating new vendor ,my code is working ,user must go to the Addresses Tab & enter address...

    but if i open existing vendor , user cant proceed without address details through my code..

    now my requirement is if user open existing vendor , User can proceed without enter address details.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,150 on at
    RE: How to know field have a value Exist in X++

    You can add code in validateWrite() method of VendTable and add your own validations there. You can also set property Mandatory to Yes in table field or data source field.

    But actually VendGroup is already a mandatory field in VendTable so you don't need to add any custom code for that.

    Also Name field is already mandatory in the vendor form (and in DirPartyTable) so you don't need to do anything for that, either.

    However I don't think it's possible to prevent saving of vendor without address. The reason is that actually the vendor needs to be saved before an address can be linked to it. So for every vendor that is created, there is a point in time when the vendor record exists without having any address. If you could block that, you would actually block creation of vendors entirely.

    You can easily notice this if you try to add an address but some mandatory fields are still missing from the vendor (such as VendGroup). In this case the system tries to save the vendor, but fails. And you can't add the address before the vendor is succesfully saved.

    Perhaps you can indeed put the address validation in the canClose() method of the form. But you must remember that it will not prevent saving of vendor, it will only prevent closing of the form once the vendor is already saved. The user can simply close AX client (or the client can crash) and you will end up with a vendor that doesn't have any address.

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

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,782 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,067 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,150

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans