web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to set Field in header to Mandatory with condition from Field in Line

(0) ShareShare
ReportReport
Posted on by

Hi experts,

I have a problem with mandatory field,

I already create the field Contract Number in PO header.

Here is the screen shoot

1854.1.png

I need to make that field (Contract Number) set to mandatory with condition.

If the Net amount >= 200000000 and the Item is Asset

then Contract Number is Mandatory.

I've tried create a modified method in Net Amount but its not working, I've tried add a condition code in init method but still not working.

Can you guys give some advise how to make it work?

Thanks and Regards,

Enggar

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

       Try it in leave method, it may work. If not please let me know. I will try it in my system.

    Thanks

    Suresh

  • Community Member Profile Picture
    on at

    Hi Suresh,

    Thanks for your reply.

    I've tried to add code to Leave Method in Datasource PurchTable

    Here is my code

    If (PurchLine.LineAmount >= 200000000)
    {
       PurchTable_WCS_NoKontrak.mandatory(true);
    }

    But still its not working

    Thanks and Regards,

    Enggar

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi Putri Enggar Ningrum Ika Pamulat,

    PurchTable_WCS_NoKontrak.mandatory(true); won't make a field mandatory, it just adds red line, however, AX won't validate it.

    Usually you have code in validateWrite() method of a table\form that checks condition you need and returns false + warning message using "checkFailed", so user cannot save a record.

  • Community Member Profile Picture
    on at

    Hi ievgen,

    Thanks for replying me,

    Yes I found valildateWrite() method in the table, and I guess I need to add validate for my custom field cuz just like you said the I made just adds red line.

    Can you show me how to add the method?

    Here is the validateWrite() from PurchTable

    public boolean validateWrite()
    {
        boolean ret;
        List                    purchTable2LineUpdateFields;
        ListEnumerator          purchTable2LineUpdateFieldsEnumerator;
        PurchTable2LineField    purchTable2LineField;
    
        ret = super();
    
        copyTaxGroupToMarkupTrans = DialogButton::No;
        if (ret && purchTable.TaxGroup != purchTable.orig().TaxGroup)
        {
            copyTaxGroupToMarkupTrans   = MarkupTrans::promptCopyTaxGroupToMarkupTrans(purchTable.TableId, purchTable.RecId);
            ret                         = copyTaxGroupToMarkupTrans != DialogButton::Cancel;
        }
    
        if (ret)
        {
            purchTable2LineUpdatePrompt = PurchTable2LineUpdatePrompt::newExecuteExtendedPrompt(purchTable, copyTaxGroupToMarkupTrans);
            // If the purchTable2LineUpdatePrompt object is null no fields are to be updated.
            if(purchTable2LineUpdatePrompt)
            {
                ret = purchTable2LineUpdatePrompt.parmExtendedPromptReturnValue();
            }
        }
    
        if (isRU
            && ret
            && purchTable2LineUpdatePrompt)
        {
            purchTable2LineUpdateFields = List::create(purchTable2LineUpdatePrompt.packedSalesPurchTableToLineUpdateFields());
    
            purchTable2LineUpdateFieldsEnumerator = purchTable2LineUpdateFields.getEnumerator();
    
            while (purchTable2LineUpdateFieldsEnumerator.moveNext())
            {
                purchTable2LineField = purchTable2LineUpdateFieldsEnumerator.current();
                if (purchTable2LineField.parmFieldId()          == PurchTable::fieldIdToInternalFieldId_W(fieldNum(PurchTable_RU, InventProfileId_RU), tableNum(PurchTable_RU))
                    && purchTable2LineField.parmUpdateLines()   == NoYes::No)
                {
                    // must be checked for possible inconsistence if user did not select to propagate inventProfileId to the order lines
                    // otherwise it will be checked on sales order validateWrite() method
                    ret = purchTable.checkInventProfile_RU(true);
                }
            }
        }
    
    
        return ret;
    }


    I dont quite know where should I put my code.

    Thanks and Regards,

    Enggar

  • Mea_ Profile Picture
    60,284 on at

    As far as I understand your requirements you need to validate field base on line amount, so why do you want to do it on purchTable?

  • Suggested answer
    Pravasti AK Profile Picture
    2,985 on at

    Hi Putri,

     Try to set mandatory fields in Table.

    DictTable dictTable;

    DictField dictField;

    TableId tableId;

    FieldId  fieldId;

    str result;

    #DictField

    ;

    dictTable = new DictTable(tablenum(salestable));

    for(fieldId=dictTable.fieldNext(0);fieldId;fieldId=dictTable.fieldNext(fieldId))

    {

    dictField =dictTable.fieldObject(fieldId);

    if(!dictField.isSystem() && bitTest(dictField.flags(),#dbf_visible) &&bitTest(dictField.flags(),#dbf_mandatory))

    {

    result += dictField.name();

    result +='\n';

    }

    }

    info(result);

  • André Arnaud de Calavon Profile Picture
    301,037 Super User 2025 Season 2 on at

    Ievgen has mentioned the problem. You are trying to make a field mandatory based on Line details. You cannot make the field mandatory in this way. If you enter lines, an execution of a validation on the contract field on the header will result, you cannot save the line. Or a validation on the header will not be executed when you don't make new changes on the header. Probably you can check for the Contract field to be filled during posting a confirmation, receipt list and/or invoice. Then raise an error if it is not filled and a user needs to correct the field before being able to send the purchase order out.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans