How to Disable table trigger in Business Central with AL extension

ChowdaryKChowdaryK Member Posts: 16
Hi,

I want to disable table trigger on item category table for Parent Category

field(2; "Parent Category"; Code[20])
{
Caption = 'Parent Category';
TableRelation = "Item Category";

trigger OnValidate()
var
ItemCategory: Record "Item Category";
ItemAttributeManagement: Codeunit "Item Attribute Management";
ParentCategory: Code[20];
begin
ParentCategory := "Parent Category";
while ItemCategory.Get(ParentCategory) do begin
if ItemCategory.Code = Code then
Error(CyclicInheritanceErr);
ParentCategory := ItemCategory."Parent Category";
end;
if "Parent Category" <> xRec."Parent Category" then
ItemAttributeManagement.UpdateCategoryAttributesAfterChangingParentCategory(Code, "Parent Category", xRec."Parent Category");
end;

Please help me

Answers

  • JJMcJJMc Member Posts: 62
    You can suscribe to the onbeforevalidate of the field, do whaever you want, then commit the changes, if there is any, and then error('') to stop the standard validate
  • ChowdaryKChowdaryK Member Posts: 16
    modify("Parent Category")
    {
    trigger OnBeforeValidate()
    begin
    "Parent Category":=rec."Parent Category";
    if rec.Parent<>'' then // custom field stored for parent category tempororly
    "Parent Category":=rec.Parent;
    end

    is this bypass on validate trigger.?

    Please help with code as I am not good in coding
  • ChowdaryKChowdaryK Member Posts: 16
    will you give me code on the subjected field.
    'You can subscribe to the onbeforevalidate of the field, do wherever you want, then commit the changes, if there is any, and then error('') to stop the standard validate'
  • ChowdaryKChowdaryK Member Posts: 16
    help me how to disable this trigger //
    [EventSubscriber(ObjectType::Table, Database::"Item Category", OnBeforeInsertEvent, '', false, false)]
    local procedure ItemCatOnBeforInsert(var Rec: Record "Item Category"; RunTrigger: Boolean)
    begin
    ItemCatValidateParentCat(Rec);
    end;
  • Developer101Developer101 Member Posts: 568
    Question is why do you want to disable the trigger for what is the end goal? A context will be helpful in giving a better solution.
    United Kingdom
  • ChowdaryKChowdaryK Member Posts: 16
    Dear Developer101 ,

    I am encountering an issue with the Parent Category value while working with LS Retail. Previously, the category structure was functioning correctly in a tree format. However, after installing the LS Retail application, I now receive the following error message:

    "Parent Category value must be ''."

    Could you please help me understand why this error is occurring? Additionally, I would appreciate guidance on how to properly implement an Item Category tree structure in LS Retail to avoid this issue.

    Thank you for your assistance. I look forward to your response. I am also contacting LS retail too.
    best regards
  • ChowdaryKChowdaryK Member Posts: 16
    This issue I have raised has been resolved. Thank you for understanding.
    i9j6pb4iz0hj.png
  • Developer101Developer101 Member Posts: 568
    What was the solution?
    United Kingdom
  • ChowdaryKChowdaryK Member Posts: 16

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"LSC Retail Item Extensions", OnBeforeItemCatValidateParentCat, '', false, false)]
    local procedure OnBeforeValidateItemCategory(var ItemCat: Record "Item Category"; var ItemCatValidateParentCat_Handled: Boolean)
    begin
    ItemCatValidateParentCat_Handled := true; // Skip the standard validation logic

    end;
Sign In or Register to comment.