Need Help with Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 02:16 PM
Dear Experts,
I am trying to populate the Business Service Offering through Business Service (I know it should be other way round) I have created a script include and the client callable script somehow I am unable to get the data in. Can someone help. If someone can guide I will be really greatful.
Script include
var GetRelatedServiceOfferings = Class.create();
GetRelatedServiceOfferings.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOfferings: function() {
var serviceId = this.getParameter('sysparm_service_sys_id');
if (!serviceId) return JSON.stringify([]);
var relTypeGR = new GlideRecord('cmdb_rel_type');
relTypeGR.addQuery('parent_descriptor', 'Depends on');
relTypeGR.addQuery('child_descriptor', 'Used by');
relTypeGR.query();
if (!relTypeGR.next()) return JSON.stringify([]);
var relTypeSysId = relTypeGR.getUniqueValue();
var result = [];
var relGR = new GlideRecord('cmdb_rel_ci');
relGR.addQuery('type', relTypeSysId);
relGR.addQuery('parent', serviceId);
relGR.query();
while (relGR.next()) {
var offering = relGR.child.getRefRecord();
if (offering && offering.getTableName() === 'service_offering') {
result.push({
sys_id: offering.getUniqueValue(),
name: offering.getDisplayValue()
});
}
}
return JSON.stringify(result);
}
});
Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearOptions('service_offering');
return;
}
var ga = new GlideAjax('GetRelatedServiceOfferings');
ga.addParam('sysparm_name', 'getOfferings');
ga.addParam('sysparm_service_sys_id', newValue);
ga.getXMLAnswer(function(response) {
var offerings = JSON.parse(response);
g_form.clearOptions('service_offering');
g_form.addOption('service_offering', '', '-- None --');
offerings.forEach(function(offering) {
g_form.addOption('service_offering', offering.sys_id, offering.name);
});
});
}
- Labels:
-
ITSM
-
ITSM: General
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 02:24 PM
if you are following CSDM, the business service and service offerings are related through reference. So you could query the service offering table which has reference of business service.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 11:55 PM - edited 06-11-2025 11:56 PM
The service offering are related to the Services with a relationship type and these fields are references in a service catalog form, hence I am looking to ensure that the information gets populated when someone selects an offering or services.
Also the auto populate feature is not helpful here in the ref fields is also not able to pull the records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2025 12:07 AM
not sure if you didn't copy it but the script include needs to have "type: 'GetRelatedServiceOfferings' " at the end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2025 12:09 AM
so what debugging did you do?
Is the script include client callable?
Is some log coming in script include?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader