Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,622 Super User 2024 Season 2 on at
    RE: How to set Field in header to Mandatory with condition from Field in Line

    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.

  • Suggested answer
    Pravasti AK Profile Picture
    Pravasti AK 2,985 on at
    RE: How to set Field in header to Mandatory with condition from Field in Line

    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);

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: How to set Field in header to Mandatory with condition from Field in Line

    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?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to set Field in header to Mandatory with condition from Field in Line

    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

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: How to set Field in header to Mandatory with condition from Field in Line

    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
    Community Member Microsoft Employee on at
    RE: How to set Field in header to Mandatory with condition from Field in Line

    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
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to set Field in header to Mandatory with condition from Field in Line

    Hi,

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

    Thanks

    Suresh

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,622 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans