GuiAllowed - stop pop up message for dimensions when creating Job from AL

samantha73samantha73 Member Posts: 77
Hi All
I'm still struggling to stop pop messages when creating a Job from code, where a user clicks an action button on quote screen and it creates a Job. Pop up message appear as usual for copy dimensions to tasks
I've initiated the Job and written below code
Job.Validate("Global Dimension 1 Code", SalesHeader."Shortcut Dimension 1 Code");
            Job.Validate("Global Dimension 2 Code", SalesHeader."Shortcut Dimension 2 Code");

Looking at the base table Job there is a piece of code that I think creates the pop up below
local procedure UpdateJobTaskDimension(FieldNumber: Integer; ShortcutDimCode: Code[20])
var
    JobTask: Record "Job Task";
    IsHandled: Boolean;
begin
    IsHandled := false;
    OnBeforeUpdateJobTaskDimension(Rec, FieldNumber, ShortcutDimCode, IsHandled);
    if IsHandled then
        exit;

    if GuiAllowed then
        if not Confirm(UpdateJobTaskDimQst, false) then
            exit;

    JobTask.SetRange("Job No.", "No.");
    if JobTask.FindSet(true) then
        repeat
            case FieldNumber of
                1:
                    JobTask.Validate("Global Dimension 1 Code", ShortcutDimCode);
                2:
                    JobTask.Validate("Global Dimension 2 Code", ShortcutDimCode);
            end;
            JobTask.Modify();
        until JobTask.Next() = 0;
end;

Couldn't find any function with HideDialog to pass a false so what options do I have? One is not to validate and try to code the whole validation thing but I might miss something or worse if the base code change in an upgrade might not do the right validation

Best Answers

  • DenSterDenSter Member Posts: 8,281
    edited 2022-08-13 Answer ✓
    There's a OnBeforeUpdateJobTaskDimension event publisher with an IsHandled parameter. You could set IsHandled to true in an event subscriber and make it exit out of the UpdateJobTaskDimension function. If you use Job Tasks, you need to copy the code in the UpdateJobTaskDimension function into the event sub and leave out the confirmation message
  • DenSterDenSter Member Posts: 8,281
    Answer ✓
    Guiallowed is a system flag, it indicates whether GUI elements can be shown. It is true when running the web client (or windows client in the NAV days), false for background sessions. You can’t set it in code, you can’t set it to false from the web client for instance

    Not sure what you mean by ‘something better’, it is what it is. You’re lucky that this function has an IsHandled flag, not all of them do

Answers

  • DenSterDenSter Member Posts: 8,281
    edited 2022-08-13 Answer ✓
    There's a OnBeforeUpdateJobTaskDimension event publisher with an IsHandled parameter. You could set IsHandled to true in an event subscriber and make it exit out of the UpdateJobTaskDimension function. If you use Job Tasks, you need to copy the code in the UpdateJobTaskDimension function into the event sub and leave out the confirmation message
  • samantha73samantha73 Member Posts: 77
    Perfect that worked..what this means is you cannot set GuiaAllowed and the only way to control this is either integration event or creating your own code. I guess if you are creating documents from an API call or Job queue GuiAllowed = false . Perhaps MS will come up with something better in a future version
  • DenSterDenSter Member Posts: 8,281
    Answer ✓
    Guiallowed is a system flag, it indicates whether GUI elements can be shown. It is true when running the web client (or windows client in the NAV days), false for background sessions. You can’t set it in code, you can’t set it to false from the web client for instance

    Not sure what you mean by ‘something better’, it is what it is. You’re lucky that this function has an IsHandled flag, not all of them do
  • JJMcJJMc Member Posts: 52
    You can launch your process in a second sesion so it don't show any messsages: STARTSESSION(........)
    This won't show any messages, confirms, etc.
  • DenSterDenSter Member Posts: 8,281
    JJMc wrote: »
    You can launch your process in a second sesion so it don't show any messsages: STARTSESSION(........)
    This won't show any messages, confirms, etc.

    True, because that starts a background session, and GuiAllowed is false there. However it also starts a new and independent transaction and I'm not sure if that is a good idea for a simple field validation. Those background sessions are supposed to be background tasks, I would not use them like this
Sign In or Register to comment.