How to set up Service and Service Offering reference fields relationship so it is bi-directional?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 07:14 AM
I am creating a catalog item and I am adding two reference fields for service and service offering. The service offering table depends on the service table. The client requirements for these two,
- When you select a Service, related Service Offerings should be available.
- If Service is blank, Service Offerings should show all.
- When you select a Service Offering, related Service should auto-populate.
- Fields should clear if no relationship is found.
I created 2 onChange catalog client scripts for Service and Service Offering. For some reason, I made the service offering reference field work but not the service field. Does anyone have scripts that do the same as this?
Here is the catalog script I use,
onChange target field - service
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
} else {
var serOff = g_form.getReference('service_offering', doTheThing);
}
function doTheThing(serOff) {
if (newValue != serOff.parent) {
alert("doesn't match");
g_form.setValue('service_offering', '');
//need to update this line of code after clear the value by adding new options.
} else {
alert("match");
return;
}
}
}
onChange target field - service offering
function onChange(control, oldValue, newValue, isLoading) {
if (newValue === '') {
g_form.clearValue('service');
return;
} else {
g_form.getReference('service_offering', returnTheServiceParent);
}
function returnTheServiceParent(bahOffering) {
g_form.setValue('service', bahOffering.parent);
}
}