Reproducing a button treatment using X++ code : Closing a Kanban with X++ code

Hi everyone,

I’m attempting to close a Kanban using code, so after debugging the process manually and changing one method ( KanbanMultiJob::newParameters() ) from protected to public, here’s the job I could come up with :

static void testKanbanJobCompletion(Args _args)
{
    KanbanMultiJobComplete      kanbanMultiJobComplete;
    KanbanMultiJob              kanbanMultiJob;
    KanbanJob                   kanbanJob;
    KanbanBoardTmpProcessJob    kanbanBoard;
    container                   kanbanCon;
    Common                      common;

    _args = new Args();

    kanbanJob       = KanbanJob::findByKanbanId("019418");                      //card 005264

    kanbanBoard.init(kanbanJob.wrkCtrResourceGroup().RecId,3,250,250,250);

    select * from kanbanBoard where kanbanBoard.Kanban == kanbanJob.Kanban;

    info(strFmt("Selected Kanban %1 Card Id %2 from kanbanBoard...",Kanban::find(kanbanBoard.Kanban).KanbanId,Kanban::find(kanbanBoard.Kanban).KanbanCardId));

    common =  kanbanBoard;

    kanbanCon = [common];

    kanbanMultiJob = kanbanMultiJob::newArgs(_args,
                                                 LeanKanbanJobStatus::Completed,
                                                 false,
                                                 kanbanCon);
    try
    {
        kanbanMultiJob.runMain(_args);
    }
    catch
    {
        info(strFmt("Error while ending Kanban n° %1.",Kanban::find(kanbanBoard.Kanban).KanbanId);
    }

    info("End of treatment!");


}

When I debug it, it does exactly the same treatment as manually clicking on “End” in the KanbanBoard, the only difference is there’s no form. So if anyone has any idea or lead, or has already crossed this kind of preoblem I’d be grateful.

Thank you!!

Solved, just had to change the runMain ( created another one ) to do directly this treatment :

public void runMainGalia(Args _args)
{

KanbanMessageBoard      kanbanMessageBoard;

            kanbanMessageBoard = KanbanMessageBoard::newStandard(_args.caller());

            try
            {
                this.runOnServer();
                kanbanMessageBoard.displayMessages();
            }
            catch (Exception::Error)
            {
                kanbanMessageBoard.displayMessages();
            }
            
}

Works like a charm!!