Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need Cancel button on form

Primm
Tera Contributor

I need a cancel button on portal that changes the state to closed complete. 

I have this from a widget that is active. 

server script:

} else if (input.action == 'cancel') {

                gr.setValue('state', 7);

                gr.comments = "[code]<b>Request Cancelled</b>[/code] by " + gs.getUserDisplayName();

                gr.update();

                var flowGR = new GlideRecord('sys_flow_context');

                flowGR.addQuery('source_record', data.sys_id);

                flowGR.query();

                flowGR.next();

                sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');

        } else if (input.action == 'complete'){

                if (gr.getTableName() == 'x_g_duas_abm_srrb')

                    gr.setValue('state', -17);

                else

                    gr.setValue('state', 3);

                gr.comments = "Review task completed by " + gs.getUserDisplayName();

                gr.update();

        }

    }

Client Controller:

 c.cancelAction = function() {

        $rootScope.$broadcast("action.initiated");

        c.server.get({

            action: 'cancel'

        }).then(function() {});

    }

   

Here is the table "x_g_duas_abm_contract_action_review" 

sys_ID  contract_action_review

"cancelled state" = 107

Please any assistance would be great.

2 REPLIES 2

Primm
Tera Contributor

Thanks, but the info you provided is for new cancel widget.

I need to edit an existing widget. Here is the info from the existing widget.

server script:

} else if (input.action == 'cancel') {

                gr.setValue('state', 7);

                gr.comments = "[code]<b>Request Cancelled</b>[/code] by " + gs.getUserDisplayName();

                gr.update();

                var flowGR = new GlideRecord('sys_flow_context');

                flowGR.addQuery('source_record', data.sys_id);

                flowGR.query();

                flowGR.next();

                sn_fd.FlowAPI.cancel(flowGR.getValue('sys_id'), 'Cancelled by submitter');

        } else if (input.action == 'complete'){

                if (gr.getTableName() == 'x_g_duas_abm_srrb')

                    gr.setValue('state', -17);

                else

                    gr.setValue('state', 3);

                gr.comments = "Review task completed by " + gs.getUserDisplayName();

                gr.update();

        }

    }

Client Controller:

 c.cancelAction = function() {

        $rootScope.$broadcast("action.initiated");

        c.server.get({

            action: 'cancel'

        }).then(function() {});

    }

Here is the "Cancelled state" = 107, and it's pulling from this table 

Here is the table "x_g_duas_abm_contract_action_review" 

sys_ID  contract_action_review