Subflow execution in a widget

tomaslindev
Mega Guru

First of all I feel the inconvenience,

I have a task in the Service Portal in which a "Add External Comment" widget must be created, which when click is opened a modal to introduce text, when it dries, a flow must be launched that introduces the comment as a public comment at the Primary_ticket. This flow will be launched as a system user, and in the public comment the person who has written will be indicated.
I have already created the correct widget button, the modal and the flow (which works correctly if I try it in the flow test section giving it a system of a universal request and putting the requested inputs), but when giving submit to the modal it does not run the flow.

I would be very grateful for some kind of help.
Thank you very much and greetings.

 

Server side: 

// =================== Enviar comentario externo vía subflow ===================
if (input && input.action === 'add_external_comment') {
    gs.info('INPUT desde cliente: ' + JSON.stringify(input));
 
    var urSysId = input.ur_sys_id;
    var commentText = input.comment_text;
 
    if (!urSysId || !commentText) {
        gs.error('Faltan datos: ur_sys_id o comment_text');
        data.result = 'missing_data';
        return;
    }
 
    try {
        var inputs = {
            'comment': commentText,
            'ur_sys_id': urSysId
        };
 
        var flowAPI = new sn_fd.FlowAPI();
        var execution = flowAPI.startSubflow('[ATC]Add External Comment to UR', inputs, 'system');
 
        if (execution) {
            gs.info('Subflow lanzado correctamente: ' + execution.getId());
            data.result = 'comment_launched';
        } else {
            gs.error('No se pudo lanzar el subflow');
            data.result = 'subflow_error';
        }
 
    } catch (e) {
        gs.error('Error al ejecutar el subflow: ' + e.message);
        data.result = 'exception';
    }
 
    return;
}

 

Client side:

 

 // ========== External Comment Modal ==========
    c.openCommentModal = function() {
        c.externalCommentText = '';
 
        var options = {
            size: 'md',
            scope: $scope,
            backdrop: 'static',
            templateUrl: 'add-external-comment-template.html'
        };
 
        instance = $uibModal.open(options);
        instance.rendered.then(function() {
            var modal = $('div.modal');
            modal.attr('aria-labelledby', 'modal-title');
        });
    };
 
    // ========== Submit External Comment ==========
   
    c.submitComment = function() {
        if (!c.externalCommentText || c.externalCommentText.trim() === '') {
            spUtil.addErrorMessage("El comentario no puede estar vacío.");
            return;
        }
 
        c.server.update({
            action: 'add_external_comment',
            comment_text: c.externalCommentText.trim(),
            author_name: c.data.currentUserName,
            ur_sys_id: c.data.ur_sys_id
        }).then(function(response) {
    var result = response && response.data ? response.data.result : null;
 
    if (result === 'comment_launched') {
        spUtil.addInfoMessage("Comentario enviado correctamente.");
        c.cancel();
    } else {
        spUtil.addErrorMessage("Error al lanzar el subflow. Código: " + result);
    }
});
    };
}
1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@tomaslindev 

it seems you already asked the same question twice in community.

I had given reply to that.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader