Set Job Task No. with extension

Hi everyone,

I’m finding a problem finding the event where I can set the “job Task No.” before the insert of the registry.

In a job card, when I’m trying to create a Job Task, I want to create it without setting the Job Task No, which I want to be filled when inserting, adding for example, the date. Which event can I sue fro this purpose? I’m trying to use the events from the “Job Task” table, but I can’t find the correct way… Is possible to develop this with extensions?

Thnak you very much

If I understand you, you want to create a job task record and automatic fill Job task no.?

You could use OnBeforeInsertEvent on job task.

Thanks for your answer [mention:b98c3821190c44a1b76031fcf72a1fc8:e9ed411860ed4f2ba0265705b8793d05].

That is the first event I tried, but still having the same issue. This is my code:

    [EventSubscriber(ObjectType::Table, Database::"Job Task", 'OnBeforeInsertEvent', '', true, true)]
    local procedure setJobTaskNo(VAR Rec: Record "Job Task")
    begin
        if Rec."Job Task No." = '' then begin
            Rec."Job Task No." := 'jobnumber';
            Rec.Modify();
        end;
    end;

I think that probably is because of using the “Rec”. If we are doing it on the “OnBeforeInsertEvent”, the Rec isn’t created yet, so it seems not to work correctly… Am I right? Or may be I’m coding the development incorrectly?

Thanks again, really appreciated

I’ve simplified the code like this, just to show a messaje int he event:

    [EventSubscriber(ObjectType::Table, Database::"Job Task", 'OnBeforeInsertEvent', '', true, true)]
    local procedure setJobTaskNo(VAR Rec: Record "Job Task")
    begin
        Message('aitor');

    end;

But the error notification appears before my message, so, the validation is made before the “OnBeforeInsertEvent”…

Turn on the debugger, where in your code are you getting a error?

My guess is that debugger will not catch this error, since the field “Job Task No.” is marked as NotBlank in the table. Server performs this verification before trying to insert the record, so it never comes to the OnBeforeInsert event. I’m not aware of any way to override this property in extensions.

Seems the only option is to fill the jon task no. in page triggers - create a page extension and do the trick in OnNewRecord / OnInsertRecord.

Thanks Alexander, I’ll work on it, and tell if it works. Really appreciate!