BPM, Workflow, and Case

BPM, Workflow, and Case

Come for answers. Stay for best practices. All we’re missing is you.

 View Only

Case Manager - Property change not saved when updated from Script Adapter widget

  • 1.  Case Manager - Property change not saved when updated from Script Adapter widget

    Posted Tue August 15, 2023 11:50 AM

    We are implementing a script on the Task Details page to change a property named "StatusTicket" but we are not being able to save the changes on the case property after the update.
    Here is the code we are using right now:
    ###############################

    debugger;
    var coord = payload.coordination;
    var workitemEdit = payload.workItemEditable;
    var solution = this.solution;
    var prefix = solution.getPrefix();
    var theController;
    var dentroSLAController;
    var slaAberturaController;
    var dataSlaAbertura = new Date();
    var sla = 2;
    var statusTicketController;
    var statusTickettxt = "Em atendimento";

    require(["icm/base/Constants", "icm/model/properties/controller/ControllerManager"],function(Constants, ControllerManager){
        var loadTopicHandler = function(context, complete, abort) {
            debugger;
            var DentroSLA = prefix + '_DentroSLAAberturaTicketAtendente';
            var SLAAbertura = prefix + '_SLAAberturaTicketAtendente';
            var StatusTicket = prefix + '_StatusTicket';
            theController = ControllerManager.bind(workitemEdit);
            dentroSLAController = theController.getPropertyController(DentroSLA);
            slaAberturaController = theController.getPropertyController(SLAAbertura);
            statusTicketController = theController.getPropertyController(StatusTicket);

            //trata data e calcula diferença entre data de abertura e sla
            var dataAberturaCase = workitemEdit.getLaunchDate();
            var extDateReg = new RegExp("[0-9]{4}-[0-9]{2}-[0-9]{2}");
            var dateFormat = extDateReg.exec(dataAberturaCase);
            var dataAberturaCaseDt =  new Date(dateFormat[0] + " 00:00:00");
            var diffDays = parseInt((dataSlaAbertura.getDate() - dataAberturaCaseDt.getDate()) / (1000 * 60 * 60 * 24), 10);

        //console.log(diffDays + " days");
            //seta novo valor no campo
            statusTicketController.set('value',statusTickettxt);
            if (slaAberturaController.get('value') == null){
                slaAberturaController.set('value',dataSlaAbertura);
                
                if (diffDays > sla){
                    dentroSLAController.set('value',true);
                }

            }

            //deixa como hidden
            //dentroSLAController.set("hidden", true);
            //slaAberturaController.set("hidden", true);
            
            complete();
        };
        
        var updateTicket = function(context, complete, abort) {
            debugger;
            ControllerManager.unbind(workitemEdit)
            complete();
        };
        debugger;
        coord.participate(Constants.CoordTopic.BEFORELOADWIDGET,loadTopicHandler);
        coord.participate(Constants.CoordTopic.BEFORECOMPLETE,loadTopicHandler);
        coord.participate(Constants.CoordTopic.BEFORESAVE,loadTopicHandler);
        coord.participate(Constants.CoordTopic.CANCEL,loadTopicHandler);
        coord.participate(Constants.CoordTopic.COMPLETE,loadTopicHandler);
        coord.participate(Constants.CoordTopic.SAVE,loadTopicHandler);
        coord.participate(Constants.CoordTopic.COMPLETE,updateTicket);
        coord.participate(Constants.CoordTopic.CANCEL,updateTicket);
        coord.participate(Constants.CoordTopic.SAVE,updateTicket);
    });

    ###############################

    How can we save the new value of the property on the case using this script I sent before?



    ------------------------------
    Veridiana Michelle Morassi Barboza
    ------------------------------