Development Tip: Service Override

There is often a time when we need to slightly modify an upstream service such as one in mantle-usl, or another Moqui component. One handy trick for doing so is to do a service override. If you have a component that depends on the component that contains the service you need, then in your services directory, you can override the service by create a file with the same path as the upstream service that contains a service with the same name.

For example: I need to override the service. So, in my component that has a component.xml that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<component xmlns:xsi="" xsi:noNamespaceSchemaLocation="" name="my-component" version="1.0.0">
    <depends-on name="mantle-usl"/>

I then create a file in my-component/service/mantle/party called PartyServices.xml that contains:

<?xml version="1.0" encoding="UTF-8"?>
<services xmlns:xsi="" xsi:noNamespaceSchemaLocation="">

    <service verb="get" noun="PartyOrganizationInfo">
        <in-parameters><parameter name="partyId" default="ec.user.userAccount?.partyId"/></in-parameters>
            <parameter name="activeOrgId"/>
            <parameter name="userOrgIds" type="List"><parameter name="userOrgId"/></parameter>
            <parameter name="filterOrgIds" type="List"><parameter name="userOrgId"/></parameter>
            <log level="warn" message="Successfully overrided service!"/>

I forgot how to do this, and had to look up how to do it, so I figured I would create a post. Hopefully this is useful!