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 NAV (Archived)

How to make mandatory fields in sales line?

(0) ShareShare
ReportReport
Posted on by 1,893

Dear Experts,

I want to restrict some fields in Sales Line tabel.
My requirement is if the below fields is blank then user can not be send for further approval process. I have added some fields in "Send Approval Btn" in page 42. But here sales line fields not accepting.

My fields are below:

Lines Unit Price Excl. Tax
Lines Unit Price Custom
Lines HSN/ SAC Code
Lines GST Group Code

SendApprovalRequest - OnAction()
TESTFIELD("SALES Order Type");
TESTFIELD("Shortcut Dimension 3 Code");
TESTFIELD("Shortcut Dimension 1 Code");

TESTFIELD("Payment Terms Code");
TESTFIELD("Currency Code");
TESTFIELD("Invoice Type");

IF ApprovalsMgmt.CheckSalesApprovalsWorkflowEnabled(Rec) THEN
ApprovalsMgmt.OnSendSalesDocForApproval(Rec);

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Not so clear... The fields listed are custom fields you’ve added in Sales Line table? If so, in the OnAction trigger you can for example loop through Sales Line for this Order and make a TESTFIELD for every field.

  • Verified answer
    CDsilva Profile Picture
    4,188 on at

    Hi MKY,

    You can write the below code on the action

    SendApprovalRequest - OnAction()

    SalesLine.SETRANGE(Document Type,SalesLine.Document Type::Order); //if order

    SalesLine.SETRANGE(Documnet No,Rec.No);

    if SalesLine.FINDSET then

    begin

    repeat

    if SalesLine.Lines Unit Price Excl. Tax ='' then

    error('It cannot be blank');

    ........repeat the above for all 4 fields

    untill SalesLine.next=0;

    end;

  • Verified answer
    Olister Rumao Profile Picture
    3,967 on at

    Hi MKY,

    On the OnValidate trigger of that you can use

    IF Rec.<FieldName> = '' THEN

    ERROR('Field cannot be blank');

    OR You can try disabling/enabling based on a variable using Enabled property of the button,

    Create a Boolean Variable say ApprovalEnable.

    Set the ApprovalEnable = FALSE on OpenPage method

    and OnValidate trigger of the particular field set the ApprivalEnavle = TRUE

    IF Rec.<FieldName> <> '' THEN

    ApprovalEnable := TRUE;

    Use the ApprovalEnable on the Enabled property of the action button.

  • manish.yadav Profile Picture
    1,893 on at

    Thank you very much. Query is resolve now.

  • manish.yadav Profile Picture
    1,893 on at

    Dear Chris,

    I have applied the code in my live database but all mandatory fields are working fine except one of my customised fields.  My complete code are below.

    SendApprovalRequest - OnAction()

    TESTFIELD("MKU Order Type");

    TESTFIELD("Shortcut Dimension 3 Code");

    TESTFIELD("Shortcut Dimension 1 Code");

    TESTFIELD("Payment Terms Code");

    TESTFIELD("Invoice Type");

    SalesLine.SETRANGE("Document Type", SalesLine."Document Type"::Order);

    SalesLine.SETRANGE(SalesLine."Document No.","No.");

    IF SalesLine.FINDSET THEN BEGIN

    REPEAT

         IF SalesLine."HSN/SAC Code" ='' THEN

         ERROR('"HSN/SAC Code" cannot be blank in Sales Line');

         IF ("Payment Terms Code"='PT-040') OR (SalesLine."Unit Price (Custom)" = 0) THEN

         ERROR('"Unit Price (Custom)" cannot be blank in Sales Line');

         IF SalesLine."Label Ins. Goods" = '' THEN

         ERROR('"Label Ins. Goods" cannot be blank in Sales Line');

         IF SalesLine."Label Ins. Packing" = '' THEN

         ERROR('"Label Ins. Packing" cannot be blank in Sales Line');

    UNTIL SalesLine.NEXT=0;

    IF ApprovalsMgmt.CheckSalesApprovalsWorkflowEnabled(Rec) THEN

     ApprovalsMgmt.OnSendSalesDocForApproval(Rec);

    END;

    I have insert the data in "Unit Price (Custom)" field but still getting the error while sending for approval, can not blank. What i need to do to resolve it. Please help me. I have attached the screenshot below.

    8371.test01.png

  • Hannes Holst Profile Picture
    5,767 on at

    Your code says "when the payment term PT-040 is selected or when no custom unit price is entered, show an error".

    In your screenshot, the payment term PT-040 is selected. Therefor you get an error-message.

    Hope this helps.

  • manish.yadav Profile Picture
    1,893 on at

    my requirement is if selected payment term is "PT-040" then user need to fill the data in sales line field Unit Price (Custom). but I am unable to write the accurate condition. Please help me to resolve it. if payment term is other, there is no need to fill the value in field : Unit Price (Custom).

  • Verified answer
    Hannes Holst Profile Picture
    5,767 on at

    [quote user="MKY"]

    my requirement is if selected payment term is "PT-040" then user need to fill the data in sales line field Unit Price (Custom). but I am unable to write the accurate condition. Please help me to resolve it. if payment term is other, there is no need to fill the value in field : Unit Price (Custom).

    [/quote]

    Sure, no problem:

    IF ("Payment Terms Code"='PT-040') AND (SalesLine."Unit Price (Custom)" = 0) THEN
      ERROR('"Unit Price (Custom)" cannot be blank in Sales Line');

    As you can see, just replace the OR with an AND.

    Your code will work then as you require.
    :-)

  • manish.yadav Profile Picture
    1,893 on at

    Thank you sir.

    It is working fine.

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 NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans