We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

zurick upgrade: workflow to start EC2 failed

Cherly
Tera Contributor

we have a workflow to start amazon ec2 server but it stop working

 

error TypeError: undefined is not a function.

 

script 

// Workflow activity definition handler class
//
// Implement activity definition handling in the onExecute method
//
// Implement any event handlers for the activity definition as a method named 'on[event_name]'
//     For example, to handle the 'cancel' event, implement an 'onCancel' method
//

workflow.includeActivityDefinition('Execute EC2 Action');

var Change_StateActivityHandler = Class.create();
Change_StateActivityHandler.prototype = Object.extendsObject(Execute_EC2_ActionActivityHandler, {

    initialize: function() {
        Execute_EC2_ActionActivityHandler.prototype.initialize.call(this);
                   
        // constants        
        this.error_noInstance      = gs.getMessage('There was no instance selected for action');
        this.info_RebootReturnFail = gs.getMessage('The action RebootInstances failed');
        this.info_RebootReturnPass = gs.getMessage('The action RebootInstances succeeded');
        this.RebootInstanceValue   = 'RebootInstances';
    },
   
    _getParams: function() {
        // get instance(s), stop activity if it does not exist
        if (gs.nil(this.js(activity.vars.instances))) {
            this.setResultFailed(this.error_noInstance);
            workflow.error(this.error_noInstance);
            activity.state = 'finished';
        }
        else
            this._addInstanceSet();
    },
   
    processResponse: function() {
        if (this.action == this.RebootInstanceValue)
            this._processReboot();
        else
            this._processStartStop();
    },
   
    _processReboot: function() {
        var XMLUtil = GlideXMLUtil;
        var doc = XMLUtil.parse(this.response.getBody());
       
        if (doc) {
            var retVal = XMLUtil.getElementValueByTagName(doc, 'return');
           
            if (!retVal) {
                this.setResultFailed(this.info_RebootReturnFail);
                workflow.error(this.info_RebootReturnFail);
                activity.state = 'finished';
            }
        }
    },
   
    _processStartStop: function() {
        var XMLUtil = GlideXMLUtil;
        var instances = [];

        var doc = XMLUtil.parse(activity.output);
       
        if (doc) {          
            var instancesSet = XMLUtil.getElementByTagName(doc, 'instancesSet');
            var instancesXml = XMLUtil.getChildrenByTagName(instancesSet, 'item');

            for (var x = 0; x < instancesXml.size(); x++) {
                var instanceXml = instancesXml.get(x);
                var instance = {};

                instance.instance_id           = '' + XMLUtil.getChildTextByTagName(instanceXml, 'instanceId');
                instance.private_dns           = '';
                instance.dns                   = '';
                instance.ip_address            = '';
                var instance_state             = XMLUtil.getChildByTagName(instanceXml, 'currentState');
                instance.instance_state        = '' + XMLUtil.getChildTextByTagName(instance_state, 'code');
                instance.instance_xml          = '' + XMLUtil.toString(instanceXml);

                instances.push(instance);
            }
        }
        workflow.setVariable('instances', instances);
    },
 
   
    _addInstanceSet: function() {
        var instances = this.js(activity.vars.instances);
        if (!gs.nil(instances)) {
            var instances_arr = instances.split(',');
            for (var i = 0; i < instances_arr.length; i++)
                this.params['InstanceId.' + (i + 1)] = instances_arr[i];
        }
    },  
   

    type: 'Change_StateActivityHandler'
});
1 REPLY 1

Dr Atul G- LNG
Tera Patron

As it is upgrade issue log a now support case.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************