Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to set up Service and Service Offering reference fields relationship so it is bi-directional?

bbf35621
Kilo Sage

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);
    }   
}

 

0 REPLIES 0