Passing Parameters from a script include into a Business Rule

matthew_hughes
Kilo Sage

I've been writing the following script include to carryout two checks on the 'u_cmdb_ci_capability_provisioning':

  • If a provider has multiple recipients for the same capability
    or
  • If there is only one Recipient and that recipient has ‘OCIR Shared Service Recipient’ = True

 

My script include is below:

 

var LBGSPCSharedServicefield = Class.create();
LBGSPCSharedServicefield.prototype = {


        existingSPCS: function() {

            var shared_service = false;

            var recipient = this.getParameter('recipient');
            var provider = this.getParameter('provider');
            var capability = this.getParameter('capability');
            //var spcRecord = this.getParameter('spcRecord');
            var spcRecord = '6670148fdb17c894581b96d5db96190c';
            var department = 'c04a04bddbb608d080b2f43c0c961901';
            var retired = 7;

            var spcRecords = new GlideRecord('u_cmdb_ci_capability_provisioning');
            spcRecords.addQuery('u_provider', provider);
            spcRecords.addQuery('u_capability', capability);
            spcRecords.addQuery('install_status', '!=', retired);
            spcRecords.addQuery('sys_id', '!=', spcRecord);
            spcRecords.query();
           

            if (spcRecords.next()) {
                gs.log('The only record to show is ' + spcRecords.getValue('sys_id'));
                //shared_service = true;
                //spcRecords.u_shared_service = true;
                //spcRecords.update();
                //gs.print('The Shared Service field has now been updated to' + spcRecords.getValue('u_shared_service'));
                return true;

            } else {
                var recipientDepartment = new GlideRecord('cmn_department');
                recipientDepartment.addQuery('u_active', true);
                recipientDepartment.addQuery('u_ocir_shared_service_recipient', true);
                recipientDepartment.addQuery('sys_id', department);
                recipientDepartment.query();
                if (recipientDepartment.next()) {
                    var recipientRecords = new GlideRecord('u_cmdb_ci_capability_provisioning');
                    recipientRecords.addQuery('install_status', '!=', retired);
                    recipientRecords.addQuery('u_recipient', recipientDepartment);
                    recipientRecords.query();
                    if (recipientRecords.next()){
                        gs.log('MH SPC record is ' + recipientRecords.getValue('sys_id'));
                        //shared_service = true;
                        //recipientRecords.u_shared_service = true;
                        //recipientRecords.update();
                        return true;
                    }
                    else {
                        return false;
                        //shared_service = false;
                    }
                }
            }return shared_service;
        },

    type: 'LBGSPCSharedServicefield'
};
 
 
When I had this reviewed, I was told that I need to pass in a gliderecord of the record I'm checking, however, I don't know what this is or how to do that. 
 
The specification of my function needs to be:

 

Input: a GlideRecord containing an SPC record

Output: A true/false value of whether it meets the criteria or not.

 

If someone could explain to me what I need to do to pass the gliderecord of the record I'm checking as well as the specification, that would be great.


5 REPLIES 5

Hi @Abhay Kumar1 I've now updated my script include to have the following function:

currentData: function(spcRecord, currentCapability, currentProvider, currentRecipient, currentStatus) {
            gs.log('MH The current UBS record is ' + spcRecord);
            gs.log('MH The current Capability is ' + currentCapability);
            gs.log('MH The current Provider is ' + currentProvider);
            gs.log('MH The current Recipient is ' + currentRecipient);
            gs.log('MH The current Status is ' + currentStatus);

            var retired = 7;

            var spcRecords = new GlideRecord('u_cmdb_ci_capability_provisioning');
            spcRecords.addQuery('u_provider', currentProvider);
            spcRecords.addQuery('u_capability', currentCapability);
            spcRecords.addQuery('install_status', '!=', retired);
            spcRecords.addQuery('sys_id', '!=', spcRecord);
            spcRecords.setLimit(10);
            spcRecords.query();

            while(spcRecords.next()) {
                gs.log('The Sys ID of this record is ' + spcRecords.sys_id);
            }
        },
 
My Business Rule includes the following code:
(function executeRule(current, previous /*null when async*/ ) {

var currentSPCDetails = new LBGSPCSharedServicefield().currentData(current.sys_id, current.u_capability, current.u_provider, current.u_recipient, current.install_status);
 
}
 
I'm wanting it to display 10 records in the logs where the ID is not the same as the current record. However, when I make a change to a record in the 'u_cmdb_ci_capability_provisioning', it doesn't seem to run the while loop. I was wondering if you knew why that was.