Skip to content

ODataService UpdateEntity

UpdateEntity action is used to update an existing entity in the specified OData service. You can also delete or update links to its navigation properties.

All the properties defined under Action are applicable to this action.

ODataService UpdateEntity Properties

Property Type Required
DeleteLinks LinkItem No
Headers object No
Properties object No
RequestOptions RequestOptions No
Target LinkQueryTarget No
UpdateLinks LinkItem No
_Type const No

List of navigation properties link to be deleted.

  • type: LinkItem[]

All array items must be of the type: LinkItem


Headers

Custom headers to be included as part of the request to the OData Service in key/value pair format

  • type: object

Properties

A list of the target entity's property names and values in key/value pairs format. Complex and Binary property types are supported.

  • type: object

RequestOptions

Options for processing of data requests


Target

This action can only be executed on a single entity. therefore the Target specifier must be configured to return only 1 entity, otherwise this action will fail


List of navigation properties link to be updated.

  • type: LinkItem[]

All array items must be of the type: LinkItem


_Type

  • type: const

The value of this property must be:

"Action.Type.ODataService.UpdateEntity"

Any following options needs to be fulfilled.

Option 1

Option 2

Option 3


Action Result

Refer to the MDK Guide to understand what an action result is.

The success ActionResult of this action is a JS object containing the updated entity. The failure ActionResult is an error message.


Examples

Update with Headers & RequestOptions

{
  "_Type": "Action.Type.ODataService.UpdateEntity",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Customers",
    "ReadLink": "{@odata.readLink}"
  },
  "Properties": {
    "CompanyName": "#Control:CompanyName/#Value",
    "ContactName": "#Control:ContactName/#Value"
  },
  "Headers": {
    "MDK-Header": "MDK"
  },
  "RequestOptions": {
    "UpdateMode": "Replace"
  }
}
{ 
  "_Type": "Action.Type.ODataService.UpdateEntity",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Customers",
    "ReadLink": "{@odata.readLink}"
  },
  "UpdateLinks": [{
    "Property": "Orders",
    "Target": {
      "EntitySet": "Orders",
      "QueryOptions": "$filter=OrderID eq '{#Page:-Previous/OrderID}'"
    }
  }]
}
{ 
  "_Type": "Action.Type.ODataService.UpdateEntity",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Customers",
    "ReadLink": "{@odata.readLink}"
  },
  "UpdateLinks": "/MyMDKApp/Rules/LinkRule.js"
}

Update binary type

{ 
  "_Type": "Action.Type.ODataService.UpdateEntity",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Customers",
    "ReadLink": "{@odata.readLink}"
  },
  "Properties": {
    "BinaryData": "#Control:Attachment/#Value/#Index:0"
  }
}

Update with Open Type Dynamic Properties

<EntityType Name="DynamicCustomers" OpenType="true">
  <Key>
    <PropertyRef Name="ID"/>
  </Key>
  <Property Name="CompanyName" Type="Edm.String" Nullable="false"/>
  <Property Name="ContactName" Type="Edm.String" Nullable="false"/>
</EntityType>

<ComplexType Name="DynamicAddress" OpenType="true">
  <Property Name="Street" Type="Edm.String" Nullable="true"/>
  <Property Name="City" Type="Edm.String" Nullable="true"/>
  <Property Name="Country" Type="Edm.String" Nullable="true"/>
</ComplexType>

In OData V4, an Open Type is a structured type (such as an entity type or complex type) that can contain dynamic properties — properties not declared in the metadata model but included dynamically at runtime in the payload.

When creating or updating entities or complex properties that include dynamic properties, the request payload (the HTTP body in a POST or PATCH operation) must explicitly include both:

  • Declared properties – defined in the metadata
  • Dynamic properties – added at runtime, often annotated with @odata.type to indicate their type

Supported EDM Types

  • Edm.Boolean
  • Edm.Byte
  • Edm.Date
  • Edm.DateTimeOffset
  • Edm.Decimal
  • Edm.Double
  • Edm.Duration
  • Edm.Guid
  • Edm.Int16
  • Edm.Int32
  • Edm.Int64
  • Edm.SByte
  • Edm.Single
  • Edm.String
  • Edm.TimeOfDay

Supported User-Defined Types (must be defined in the metadata document):

  • Complex Types
  • Enum Types

Collections:

  • Collections are supported using the format: Collection(SupportedType).

The format of the OData V4 @odata.type property is #Namespace.TypeName.

Open types are currently supported only for MBT generated OData services. The # prefix and the Edm. namespace are optional.

Default Type Inference (when @odata.type is omitted)

JSON Value Default OData Type Notes
true Edm.Boolean Boolean literal
1 Edm.Int64 Integer literal
1.23 Edm.Double Floating-point literal
"Hello" Edm.String String literal
null Requires explicit @odata.type Type cannot be inferred
{
  "_Type": "Action.Type.ODataService.UpdateEntity",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "DynamicCustomers",
    "ReadLink": "{@odata.readLink}"
  },
  "Properties": {
    "CompanyName": "#Control:CompanyName/#Value",
    "ContactName@data.type": "Edm.String",
    "ContactName": "#Control:ContactName/#Value",
    "Address": {
      "@data.type": "MyNamespace.Address",
      "Street": "#Control:Street/#Value",
      "City": "#Control:City/#Value",
      "Country": "#Control:Country/#Value"
    },
    "Emails@data.type": "Collection(Edm.String)",
    "Emails": [
      "Russell@example.com",
      "Russell@contoso.com"
    ]
  },
  "Headers": {
    "MDK-Header": "MDK"
  },
  "RequestOptions": {
    "UpdateMode": "Replace"
  }
}