Accessing the parent script include methods and variable

Community Alums
Not applicable

Hello, I am dealing with a project that requires me to edit the OOTB script include. However, the platform does not allow editing directly, but only by overriding base class functions(extension of the parent). I tried to work from the child class but I cannot find a way to access the variables from the parent because they are not declared with syntax then. or the method itself does not return an actual value which I can use. 

Please find below the classes:

Child class - I am trying to push a value to the array and then use the condition for case 'biennially'. Also the comments are written in order to kind of express what I want to achieve in the script. They do not actually work.

 

var ControlAttestationUtils = Class.create();
ControlAttestationUtils.prototype = Object.extendsObject(ControlAttestationUtilsBase, {
	
	/** Override base class functions here. **/
	intialize:function() {
// 		ControlAttestationUtilsBase.prototype.checkAndMoveControlsToAttestByFrequency.apply(this, arguments);
	},
	
// 		checkAndMoveControlsToAttestByFrequency: function() {
// 		this.attestation_periodicity.push('biennially');
	    
            
//           switch(this.frequency) {
// 			  case 'biennially':
// 				  lastAttested.add....
// 				   }
// 		  if (now >= lastAttested) {
//                     control.state = 'attest';
//                     control.update();
//                 }
	
// 	}
// 	},
	
	
	type: 'ControlAttestationUtils'
});
	
// 	}
// 	},
	
	
	type: 'ControlAttestationUtils'
});

 

 

Parent class - OOTB

 

var ControlAttestationUtilsBase = Class.create();
ControlAttestationUtilsBase.prototype = {
    initialize: function() {},

    checkAndMoveControlsToAttestByFrequency: function() {
        var control = new GlideRecord("sn_compliance_control");
        control.addQuery('state', 'IN', 'review,monitor');
        control.query();

        var now = new GlideDateTime();
        var arrayUtil = new global.ArrayUtil();
        var attestation_periodicity = new Array('daily', 'weekly', 'monthly', 'quarterly', 'semi_annually', 'annually');


        while (control.next()) {
            //get the frequency of the control. No action required for controls whose frequency is not one of 
            //periodic attestations
            var frequency = control.frequency + '';
            if (!arrayUtil.contains(attestation_periodicity, frequency)) {
                continue;
            }
            // Get the time of the last attestation
            var attestationQ = new GlideRecord('asmt_assessment_instance_question');
            attestationQ.addQuery('source_id', control.getUniqueValue());
            attestationQ.orderByDesc('sys_updated_on');
            attestationQ.query();

            if (attestationQ.next()) {
                var lastAttested = new GlideDateTime(attestationQ.sys_updated_on + '');
                switch (frequency) {
                    case 'daily':
                        lastAttested.addDaysUTC(1);
                        break;
                    case 'weekly':
                        lastAttested.addWeeksUTC(1);
                        break;
                    case 'monthly':
                        lastAttested.addMonthsUTC(1);
                        break;
                    case 'quarterly':
                        lastAttested.addMonthsUTC(3);
                        break;
                    case 'semi_annually':
                        lastAttested.addMonthsUTC(6);
                        break;
                    case 'annually':
                        lastAttested.addYearsUTC(1);
                }
                if (now >= lastAttested) {
                    control.state = 'attest';
                    control.update();
                }
            }
        }
    },

    type: 'ControlAttestationUtilsBase'
};

 

 

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

The call you make in the initialize method of ControlAttestationUtils (which is misspelled b.t.w.) is wrong. Usually you only need to call the base class' same initialize method. Though in this case it is not needed as the base class does not execute anything anyway.

That said a class that extends another class can only access public members of the base class. Given that ControlAttestationUtilsBase exposes no public properties (only public method checkAndMoveControlsToAttestByFrequency) you will not be able to access anything. So all you can do is re-define method checkAndMoveControlsToAttestByFrequency re-building it basically from scratch.

So your implementation would look something like:

var ControlAttestationUtils = Class.create();

ControlAttestationUtils.prototype = Object.extendsObject(ControlAttestationUtilsBase, {
	checkAndMoveControlsToAttestByFrequency: function () 
		// add custom code from scratch
	},

	type: 'ControlAttestationUtils'
});

View solution in original post

4 REPLIES 4

-O-
Kilo Patron
Kilo Patron

The call you make in the initialize method of ControlAttestationUtils (which is misspelled b.t.w.) is wrong. Usually you only need to call the base class' same initialize method. Though in this case it is not needed as the base class does not execute anything anyway.

That said a class that extends another class can only access public members of the base class. Given that ControlAttestationUtilsBase exposes no public properties (only public method checkAndMoveControlsToAttestByFrequency) you will not be able to access anything. So all you can do is re-define method checkAndMoveControlsToAttestByFrequency re-building it basically from scratch.

So your implementation would look something like:

var ControlAttestationUtils = Class.create();

ControlAttestationUtils.prototype = Object.extendsObject(ControlAttestationUtilsBase, {
	checkAndMoveControlsToAttestByFrequency: function () 
		// add custom code from scratch
	},

	type: 'ControlAttestationUtils'
});

Community Alums
Not applicable

Yes, I thought the same way. There is no way to access that method as no value is returned or accessible through the keyword .this.  

Actually the method technically can be called, e.g:

	checkAndMoveControlsToAttestByFrequency: function () 
		ControlAttestationUtilsBase.prototype.checkAndMoveControlsToAttestByFrequency.apply(this);
	},

just that there is not point in doing so for the reasons mentioned by you.

Community Alums
Not applicable

Yes, indeed. You mentioned in the previous post for my calculator idea.