Updater case 1: Root and resolved value have no common ancestor

In some cases, the root entity and the resolved value do not share a common ancestor. This typically occurs when one or both entities are not part of any graph, such as the claim graph or policy graph.

For example, suppose you add a foreign key from Activity to User to track an activity's backup user. In this situation, there is no entity (such as a claim or an account) that owns both the activity and the user.

Using the KeyableBeanJsonValueResolver

When the two entities do not share a common parent, you can use the KeyableBeanJsonValueResolver (gw.rest.core.pl.framework.v1.refs.KeyableBeanJsonValueResolver). For example:

"updaters": {
  "Activity": {
    "properties": {
      "backupUser_Ext": {
        "path": "Activity.BackupUser_Ext",
        "valueResolver": {
          "typeName": "gw.rest.core.pl.framework.v1.refs.KeyableBeanJsonValueResolver"
        }
      }
    }
  }
}

Disabling reference by refid

By default, the KeyableBeanValueResolver supports both reference by id and refid. You can disable reference by refid by adding the following code to the valueResolver property:
"setByRefid": false

For example, the following updater for backupUser_Ext disables reference by refid.

"updaters": {
  "Activity": {
    "properties": {
      "backupUser_Ext": {
        "path": "Activity.BackupUser_Ext",
        "valueResolver": {
          "typeName": "gw.rest.core.pl.framework.v1.refs.KeyableBeanJsonValueResolver",
          "setByRefid:" false
        }
      }
    }
  }
}

Using an entity-specific value resolver

Cloud API also provides value resolvers for specific base configuration entities. For example, there is a UserJsonValueResolver for foreign key fields that reference the User entity. You could use this in place of the KeyableBeanJsonValueResolver. For example:

"updaters": {
  "Activity": {
    "properties": {
      "backupUser_Ext": {
        "path": "Activity.BackupUser_Ext",
        "valueResolver": {
          "typeName": "gw.rest.core.pl.admin.v1.group.UserJsonValueResolver"
        }
      }
    }
  }
}

You can find a list of entity-specific value resolvers in Studio by executing a Navigate > File command (CTRL + SHIFT + N) and entering "valueresolver". Be aware that the entity-specific value resolvers may have special behaviors to enable common Cloud API use cases. These behaviors may not be appropriate for an updater to a custom foreign key. Whenever you use a entity-specific value resolver, Guidewire recommends testing the associated PATCH and POST behaviors thoroughly.

Complete code sample for case 1

The following code snippets define a new foreign key property where the root and foreign key entities have no common ancestor. In this example, the Activity resource has a backupUser_Ext property that references the User entity.

Data model extension

File name: Activity.etx

<extension
  xmlns="http://guidewire.com/datamodel"
  entityName="Activity">
    ...
    <foreignkey
      fkentity="User"
      name="BackupUser_Ext"
      nullok="true"/>
    ...

Schema file extension

File name: common_ext-1.0.schema.json

"definitions": {
  "Activity": {
    "properties": {
      "backupUser_Ext": {
        "title": "BackupUser_Ext",
        "description": "The backup user who can complete the activity if the assigned user is on vacation",
        "$ref": "#/definitions/SimpleReference",
        "x-gw-extensions": {
          "resourceType": "User"
        }
      },
      ...

Mapping extension file

File name: common_ext-1.0.mapping.json

"mappers": {
  "Activity": {
    "properties": {
      "backupUser_Ext": {
        "path": "Activity.BackupUser_Ext.RestV1_AsReference",
        "mapper": "#/mappers/ResourceReference"
      },

Updater extension file

File name: common_ext-1.0.updater.json

(This example assumes use of the entity-specific UserJsonValueResolver, and reference by refid is allowed.)

"updaters": {
  "Activity": {
    "properties": {
      "backupUser_Ext": {
        "path": "Activity.BackupUser_Ext",
        "valueResolver": {
          "typeName": "gw.rest.core.pl.admin.v1.group.UserJsonValueResolver"
        }
      },