Transferring script from a background script to a script include and business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 01:17 AM
I'm trying the value of the Shared Service field of an SPC record based on the value of a field within a Department record. At the moment, I've got it working in a background script as below:
var test = new GlideRecord('u_cmdb_ci_capability_provisioning');
var provider = '1a1441c7c3fd1e909447fc37050131ae';
var capability = '42151005dbb2b748d84b9a2adb9619a4';
var retired = 7;
test.addQuery('u_provider', provider);
test.addQuery('u_capability', capability);
test.addQuery('install_status', '!=', retired);
test.query();
gs.log("The count is " + test.getRowCount());
if(test.getRowCount() > 1){
gs.log("The total number of records is " + test.getRowCount());
test.u_shared_service = true;
test.updateMultiple();
}
else if (test.getRowCount() == 1) {
while(test.next()){
gs.print('The value of the Shared Service Recipient field is ' + test.name);
if (test.u_recipient.u_ocir_shared_service_recipient == true) {
gs.log('This is true');
test.u_shared_service = true;
test.update();
}
else{
gs.log('This is false');
test.u_shared_service = false;
test.update();
}
}
}
However, what I'm wanting to do is transfer this functionality so that it works on a script include when it's triggered by a business rule. I've tried doing at as the following in my script include:
I'm wanting my my script include to refer to the current SPC records that are being updated by the affected department record. Does anyone know how I do this? The background script works because I've specified the Provider and Capability fields, but how do I do it in a script include where it refers to the current values?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 05:34 AM - edited 11-19-2024 05:34 AM
I'm not sure if "current" is a reserved keyword. Maybe try renaming it in your script include to something else?
Or maybe you could edit your Business Rule to send 2 parameters like this:
var currentSPCDetails = new LBGSPCSharedServicefield().currentDepartment(current.u_provider, current.u_capability);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 06:32 AM
Hi @JenniferRah In my business rule, I've done the following:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 06:50 AM
When you send the current.u_provider to the script include, it sends the sys_id, so you don't need to do provider.getValue('sys_id') in the addQuery statement. You just need to use provider and capability. You can do a gs.log statement above it to show what is being sent if you want to be sure you are getting the right info.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 06:54 AM
I just noticed you said this:
The department table does not have a field called capability or provider as they come from the u_cmdb_ci_capability_provisioning table
If the current record that the business rule is running on doesn't have a capability or provider field, then none of this will work. You are trying to use that record to do your query, so I'm confused as to what you are trying to search on.