Creating a decision / choice action plan item

When a task is created via an execution engine plan you are able to define action plan items that allow the user to make a choice.

Use this snippet to add in your choice to the action plan.

Note that the selected choice is placed into the variable ctx.outcomeChoiceId and this will be used in the evaluation of the gateway

/***************************************************************************************************

    STEP - PROCESS SUMMONS

****************************************************************************************************/


var processSummons = function(ev, ctx, log) {

    log.Information(ctx.planName + ": Started processSummons '" + ctx.sharedoId + "'");

    

     var allocateOdsId = actions.sharedo.GetAllocatedOdsId(ctx.sharedoId, "alg-lookup-matter-owner");

       var gatewayHeaderC2A = actions.sharedo.BuildActionPlanItem()

            .WithDescription("VALID SUMMONS")

            .AddInformation()

            .Build();

        

            //investigation gateway

            var summonsGateway = actions.sharedo.BuildActionPlanItem()

            .WithDescription("Gateway: Is initial summons valid?")

            .MarkRequired()

            .AddChoice(JSON.stringify([

                {

                    meaning: "pathwaySummonsValid",

                    description: "Summons is valid"

                },

                {

                    meaning: "pathwaySummonsNotValid",

                    description: "Summons is invalid"

                }

                    

            ]))

            .Build();

//choice is placed into ctx variable that can be passed to gateway function

        ctx.outcomeChoiceId = summonsGateway.Id.ToString();



    ctx.iniActionId = Guid.NewGuid();

    var initActionTask = actions.sharedo.BuildTask()

        .ForSharedo(ctx.sharedoId)

        .WithId(ctx.iniActionId)

        .OfType("task")

        .DueOn(actions.sharedo.AddWorkingDays(DateTime.UtcNow, 1))

        .WithTitle("Process Initial Summons")

        .WithDescription("Process Initial Summons")

        .Assign("primary-owner").To(allocateOdsId)

        .WithTag("Pleadings")

        .WithProcessTag("ALG-PROC-PL-001-002-001")

        .OnPhase("task-done", "gatewayEvaluation")

        .OnPhase("task-done", "docExpStampedMemo")

        .WithActionPlan()

            .WithTitle("Action Plan")

            .AddItem(gatewayHeaderC2A)

            .AddItem(summonsGateway)

        .Build()

        .Save();


    log.Information(ctx.planName + ": Finished Process Summons task '" + ctx.sharedoId + "'");   

};


/***************************************************************************************************

  GATEWAY EVALUATION


****************************************************************************************************/


var gatewayEvaluation = function (ev, ctx, log) {

        

    log.Information(ctx.planName + ": Started gatewayEvaluation '" + ctx.sharedoId + "'");

    log.Information("Choice was:... " + ctx.outcomeChoiceId);

    

    var actionPlan = getActionPlanForSharedo(ctx.iniActionId);

    if (!actionPlan) {

        //End here as you should always have an action plan at this point.

    }


    var items = actionPlan.items;

    var item = {};

    for (var i = 0; i < items.Count; i++) {

        log.Information(ctx.planName + ": items[i].id '" + items[i].id + "'");

        if (ctx.outcomeChoiceId == items[i].id)

            item = items[i];

    }

    


    //If the summons is invalid then create a document expectation for the valid summons

    if (item.value === "pathwaySummonsNotValid") {

        

      

        var allocateOdsId = actions.sharedo.GetAllocatedOdsId(ctx.sharedoId, "lookup-matter-owner");


        var gatewayHeaderC2A = actions.sharedo.BuildActionPlanItem()

            .WithDescription("VALID SUMMONS")

            .AddInformation()

            .Build();

            //investigation gateway


        var summonsGateway = actions.sharedo.BuildActionPlanItem()

            .WithDescription("Gateway: Is initial summons valid?")

            .MarkRequired()

            .AddChoice(JSON.stringify([

                {

                    meaning: "pathwaySummonsValid",

                    description: "Summons is valid"

                },

                {

                    meaning: "pathwaySummonsNotValid",

                    description: "Summons is invalid"

                }

                    

            ]))

            .Build();


        ctx.outcomeChoiceId = summonsGateway.Id.ToString();

    

       var updateHeaderC2A = actions.sharedo.BuildActionPlanItem()

            .WithDescription("UPDATE DETAILS")

            .AddInformation()

            .Build();

    

       var action1 = actions.sharedo.BuildActionPlanItem()

            .WithDescription("Key Date: Set Summons Served Date if summons valid")

            .AddCheckbox()

            .MarkRequired()

            .WithCallToAction

                 (

                    actions.sharedo.BuildCallToAction()

                        .WithDisplay("Key Dates", "fa-pencil")

                        .WithCommandForSharedo

                        (

                            "edit-key-dates",

                            ctx.sharedoId

                        )

                        .Build()

                )

                .Build();



        var action2 = actions.sharedo.BuildActionPlanItem()

            .WithDescription("Capture: Case Status")

            .AddCheckbox()

            .MarkRequired()

            .WithCallToAction

                 (

                    actions.sharedo.BuildCallToAction()

                        .WithDisplay("Case Status", "fa-pencil")

                        .WithCommandForSharedo

                        (

                            "edit-sharedo",

                            ctx.parentMatterId

                        )

                        .Build()

                )

                .Build();

    

        

        var action3 = actions.sharedo.BuildActionPlanItem()

            .WithDescription("Capture: Case Parties")

            .AddCheckbox()

            .WithCallToAction

                (

                    actions.sharedo.BuildCallToAction()

                        .WithDisplay("Participants", "fa-users")

                        .WithCommandForSharedo("sharedo-manage-participants", ctx.parentMatterId)

                        .Build()

                )

                .Build();

    

        ctx.revSumDocExId = Guid.NewGuid();

        var revSumDocExTask = actions.sharedo.BuildTask()

            .ForSharedo(ctx.sharedoId)

            .WithId(ctx.revSumDocExId)

            .OfType("task-activity-document-expectation")

            .DueOn(actions.sharedo.AddWorkingDays(DateTime.UtcNow, 5))

            .WithTitle("Revised Summons Expected")

            .WithDescription("Revised Summons Expected")

            .Assign("primary-owner").To(allocateOdsId)

            .WithTag("Pleadings")

            .WithProcessTag("ALG-PROC-PL-001-002-001-003")

            .OnComplete("gatewayEvaluation")

            //.OnReminderDue("legalRepTelChaser").At(0).Hours

            //.WithAttribute("FromRecipientId", ctx.clientRole)

            .WithActionPlan()

                .WithTitle("Action Plan")

                .AddItem(gatewayHeaderC2A)

                .AddItem(summonsGateway)

                .AddItem(updateHeaderC2A)

                .AddItem(action1)

                .AddItem(action2)

                .AddItem(action3)

            .Build()

         .Save();




    }

   




    log.Information(ctx.planName + ": Finished gatewayEvaluation '" + ctx.sharedoId + "'");

    

};