Regarding service_offering table

Madhusagar Pal1
Tera Expert

Hi All

I have query regarding service_offering table.

Based on the service_classification field parent reference values need to show.

For example service_classification is technical service then technical service related records needs to show in parent reference field. And service_classification is business service then Business service related records needs to show in parent reference field. 

Parent table is reference from cmdb_ci_service table.

Please let me know how to achieve this using reference qualifier.

Thanks & Regards,

Madhu.

1 REPLY 1

pratiksha5
Mega Sage

Open the service_offering table definition.
Find the parent field (which is a reference field).
Configure the reference qualifier script for the parent field.

The reference qualifier script can be written in JavaScript and should be based on the value of the service_classification field. Here's a sample script that demonstrates the logic you described:

(function() {
// Get the current value of the 'service_classification' field
var serviceClassification = current.service_classification;

// Create a new GlideRecord object for the 'cmdb_ci_service' table
var parentGR = new GlideRecord('cmdb_ci_service');

// Check the value of 'service_classification' and set the appropriate query
if (serviceClassification == 'technical service') {
parentGR.addQuery('classification', 'technical');
} else if (serviceClassification == 'business service') {
parentGR.addQuery('classification', 'business');
}

// Execute the query and set the reference qualifier
parentGR.query();
current.parent.setRefQual('sys_idIN' + getSysIds(parentGR));

// Function to get a comma-separated list of sys_ids from a GlideRecord
function getSysIds(gr) {
var sysIds = [];
while (gr.next()) {
sysIds.push(gr.sys_id);
}
return sysIds.join(',');
}
})();