Parameters within Script include not generating any results

matthew_hughes
Kilo Sage

I've got a script include with 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();
            gs.log('MH Number of records found: ' + spcRecords.getRowCount());

            while(spcRecords.next()) {
                gs.log('The Sys ID of this record is ' + spcRecords.sys_id);
            }
        },

        previousData: function(spcRecord, previousCapability, previousProvider, previousRecipient) {
            gs.log('MH The current UBS record is ' + spcRecord);
            gs.log('MH The previous Capability is ' + previousCapability);
            gs.log('MH The previous Provider is ' + previousProvider);
            gs.log('MH The previous Recipient is ' + previousRecipient);
        },
 
The script for my business rule is:
var currentSPCDetails = new LBGSPCSharedServicefield().currentData(current.sys_id, current.u_capability, current.u_provider, current.u_recipient, current.install_status);
 
The business rule triggers if either the recipient, capability or provider fields change. What I've found is that if I change either of the fields, the following logs appear:
matthew_hughes_0-1731585789580.png

 

However, I've also tried copying the function into a background script:

var retired = 7;
 
var spcRecords = new GlideRecord('u_cmdb_ci_capability_provisioning');
            spcRecords.addQuery('u_provider', '7e4692b81bae9550d1c4dbd6b04bcbef');
            spcRecords.addQuery('u_capability', 'd9155cc1dbb2b748d84b9a2adb9619c0');
            spcRecords.addQuery('install_status', '!=', retired);
            spcRecords.addQuery('sys_id', '!=', '4e08c3a11b0950103929971f2e4bcbe7');
spcRecords.setLimit(10);
            spcRecords.query();
gs.log('MH Number of records found: ' + spcRecords.getRowCount());
 
while(spcRecords.next()) {
gs.log('The Sys ID of this record is ' + spcRecords.sys_id);
}
 
When I run the background script, I get the required results:
matthew_hughes_1-1731586083317.png

 

 Can somebody explain where I'm going wrong because I want the parameters in my function to align correctly within my gliderecord 

 

 
12 REPLIES 12

SumanthDosapati
Mega Sage
Mega Sage

Just check your sysids in background script once.

the below line in bg script

spcRecords.addQuery('u_provider', '7e4692b81bae9550d1c4dbd6b04bcbef');

but there in script include logs, there is no record that printed 7e4692b81bae9550d1c4dbd6b04bcbef

 

Regards,

Sumanth

Hi @SumanthDosapati 

 

I've just updated a record and the business rule has triggered. It seems that I was looking at the wrong area. It seems to now get the right results according to the logs:

matthew_hughes_1-1731587928880.png

 

However though, I need to know why it's not showing the results in my while loop:

 
while(spcRecords.next()) {
                gs.log('The Sys ID of this record is ' + spcRecords.getValue('sys_id'));
            }

 

Brad Bowman
Kilo Patron
Kilo Patron

It looks like in the background script you've hard-coded 3 sys_ids that are different than the Business Rule test case, so this isn't a great test.

Ok. How would I get Sys IDs to those parameters in my script include?