SBX - Search With Button

SBX - Forum Post Title

How to make mandatory fields in sales line?

Microsoft Dynamics NAV Forum

MKY asked a question on 8 May 2018 12:41 PM
My Badges

Question Status

Verified

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

Reply
Suggested Answer

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.

Reply
Chris D'silva responded on 8 May 2018 10:31 PM
My Badges
Verified Answer

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;

Reply
Olister Rumao responded on 9 May 2018 3:53 AM
My Badges
Verified Answer

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.

Reply
MKY responded on 9 May 2018 5:30 AM
My Badges

Thank you very much. Query is resolve now.

Reply
MKY responded on 14 Jun 2018 7:55 AM
My Badges

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.

Reply
Hannes Holst responded on 14 Jun 2018 9:41 AM
My Badges

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.

Reply
MKY responded on 15 Jun 2018 2:30 AM
My Badges

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

Reply
Hannes Holst responded on 15 Jun 2018 3:30 AM
My Badges
Verified Answer

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

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.
:-)

Reply
MKY responded on 15 Jun 2018 3:40 AM
My Badges

Thank you sir.

It is working fine.

Reply
Chris D'silva responded on 8 May 2018 10:31 PM
My Badges
Verified Answer

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;

Reply
Olister Rumao responded on 9 May 2018 3:53 AM
My Badges
Verified Answer

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.

Reply
Hannes Holst responded on 15 Jun 2018 3:30 AM
My Badges
Verified Answer

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

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.
:-)

Reply
Suggested Answer

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.

Reply

SBX - Two Col Forum

SBX - Migrated JS