axaptax++dynamics-ax-2012-r3

Controlling records with the same field value AX 2012


I have a table which name PaymentLines and i want to control dueDate field of records which have same InvoiceId value. If there is a different dueDate value, info -> Records with the same InvoiceId value cannot have different dueDate values

How can i do this?

enter image description here


Solution

  • It depends when you want to control for example if you want to do the control when you put the value in DueDate field overwrite Modified event of this field in datasource PaymentLines.

    PaymentLines PaymentLinesCheck;
    
    ;
    
    select PaymentLinesCheck where PaymentLinesCheck.InvoiceId == PaymentLines.InvoiceId &&
                                   PaymentLinesCheck.DueDate != PaymentLines.DueDate;
    if(PaymentLinesCheck)
    {
        info("Records with the same InvoiceId value cannot have different dueDate values");
        //If you want to show an error message
        //error("Records with the same InvoiceId value cannot have different dueDate values");
        PaymentLines.DueDate = DateNull();        
    }