Hi Pragya,
I don't know what your enum values are. But here, I have created a custom enum with a default value of blank.
enum 50152 InvoiceCategory { Extensible = true; value(0; MyValue1) { Caption = ''; } value(1; MyValue2) { Caption = 'Value 2'; } value(3; MyValue3) { Caption = 'Value 3'; } }
To validate your "Invoice Category" field with the "Free Text" field, add this code
if (PurchaseHeader."Free Text" = '') then Error('Narration field is blank on Purchase Order. Kindly fill the same to sent PO for approval'); if (PurchaseHeader."Invoice Category" = InvoiceCategory::MyValue1) then Error('Narration field is blank on Purchase Order. Kindly fill the same to sent PO for approval');
Regards
I used this.I wanted to make aone more field mandatory which is an Enum.Can i add that here as well like this ?
Hi Pragya752,
Try this code. It will work for you in runtime 9.0
codeunit 50156 TestCodeUnit { [EventSubscriber(ObjectType::Codeunit, Codeunit::"Approvals Mgmt.", 'OnBeforeCheckPurchaseApprovalPossible', '', false, false)] local procedure OnBeforeCheckPurchaseApprovalPossible(PurchaseHeader: Record "Purchase Header"; var Result: Boolean; var IsHandled: Boolean); begin if (PurchaseHeader."Free Text" = '') then Error('Narration field is blank on Purchase Order. Kindly fill the same to sent PO for approval'); end; }
Regards
I want this field to be mandatory before it sending for approval
Support for using Identifiers instead of Literals in event subscribers.' is not available in runtime version '9.0'. The supported runtime versions are: '11.0' or greater this error is coming.
let me try this
just adding some additional information here.
you can try using the OnBeforeCheckPurchaseApprovalPossible event,
codeunit 52452 TestCodeUnit { [EventSubscriber(ObjectType::Codeunit, Codeunit::"Approvals Mgmt.", OnBeforeCheckPurchaseApprovalPossible, '', false, false)] local procedure OnBeforeCheckPurchaseApprovalPossible(var PurchaseHeader: Record "Purchase Header"; var Result: Boolean; var IsHandled: Boolean); begin if (PurchaseHeader."Free Text" = '') then Error('Narration field is blank on Purchase Order. Kindly fill the same to sent PO for approval'); end; }
It runs before the purchase order is sent for approval, so you can use it to add your validation check and prevent the order from being sent if the field is empty.
Regards.
yes, if you write code in above event then whenever you click on 'send approval request' the system will check if the field is entered or not.
if not then show error
This field should be mandatory before sending the Sales Invoice under Approval Workflow.How can i make this field mandatory
Please add your verification in OnAfterCheckSalesApprovalPossible event
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,219 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156