Set-Client
  • 5 Minutes to read
  • Dark
    Light
  • PDF

Set-Client

  • Dark
    Light
  • PDF

Article summary

Summary

Updates an existing client.

Set-Client
    -Entry
    -BypassCustomFieldValidation

Returns a client object.

Parameters

Parameter

Type

Required?

Notes

Entry

Client Object

Yes


BypassCustomFieldValdiation

Switch

No, Defaults to false

Ignores required field requirement for custom fields when the entry is saved.

Examples

Updates an existing client

# Update an existing client

# A common flow for updating existing data is to first retrieve the data using the GET
# command, update specific fields, and then provide the modified data back using the SET command.

$entry = Get-Client -Id 67

# In this example, we want to update the "Active" system field to false:
$entry.Active = $false

# We also want to update a basic text custom field named "Main Contact Name" to "Cecil Hudson"
$mainContactNameField = $entry.Fields | Where-Object { $_.Label -eq "Main Contact Name" }

# This is a safety check to make sure that a value exists. For example, the value object may
# not exist on a field because the custom field was added after the entry already existed.
if ($null -eq $mainContactNameField.Value) {
  $mainContactNameField.Value = @{}
}

# Here, we update the 'ValueAsString' property of the value because our custom field is a text-
# based field. If this was a whole number, you would use 'ValueAsNumber', a decimal would be
# 'ValueAsDecimal', a yes/no field would be 'ValueAsBoolean', and a date field would be 'ValueAsDate'
$mainContactNameField.Value.ValueAsString = "Cecil Hudson"

# Save the modified client
$data = Set-Client -Entry $entry

# Output some information to help indicate that the client was updated
Write-Output "Client $($data.ClientId) was updated"

# For debug purposes, convert the data to output as JSON so we can see all the fields
Write-Output ""
Write-Output "JSON Results:"

$jsonOutput = $data | ConvertTo-Json -Depth 10

# Output the data
Write-Output $jsonOutput
Client 67 was updated

JSON Results:
{
  "ClientId": 67,
  "Name": "QuantumTech v. CyberInnovate",
  "Reference": "QT00001",
  "Active": false,
  "IsFavorite": false,
  "NumberOfMatters": 0,
  "NumberOfProjects": 0,
  "NumberOfTasks": 0,
  "NumberOfMediaLogEntries": 0,
  "NumberOfVolumes": 0,
  "NumberOfBillingEntries": 0,
  "NumberOfComments": 0,
  "FirstProjectCreatedOnDate": null,
  "LastProjectCreatedOnDate": null,
  "CreatedByFullName": "Max Miller",
  "CreatedById": "25a34a2f-e3d8-4690-88f5-6b399cf88c4c",
  "CreatedOn": "2024-03-05T15:11:14.9089738+00:00",
  "CreatedBy": null,
  "LastUpdatedByFullName": "Max Miller",
  "LastUpdatedById": "25a34a2f-e3d8-4690-88f5-6b399cf88c4c",
  "LastUpdatedOn": "2024-04-17T12:33:05.3342775+00:00",
  "LastUpdatedBy": null,
  "Fields": [
    {
      "FieldId": 10,
      "ObjectId": 1,
      "DataTypeId": 1,
      "DataTypeName": "Basic Text",
      "Label": "Main Contact Name",
      "IsRequired": false,
      "Position": 0,
      "Guid": 1475776072753,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": {
        "ObjectFieldValueId": 2164,
        "ObjectFieldId": 10,
        "ObjectId": 1,
        "PrimaryKeyId": 67,
        "ValueAsString": "Cecil Hudson",
        "ValueAsBoolean": null,
        "ValueAsNumber": null,
        "ValueAsDecimal": null,
        "ValueAsDate": null,
        "ReferenceObject": null
      },
      "ReferenceObject": null
    },
    {
      "FieldId": 14,
      "ObjectId": 1,
      "DataTypeId": 2,
      "DataTypeName": "Rich Text",
      "Label": "Client Address",
      "IsRequired": false,
      "Position": 3,
      "Guid": 1476994440044,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": {
        "ObjectFieldValueId": 2165,
        "ObjectFieldId": 14,
        "ObjectId": 1,
        "PrimaryKeyId": 67,
        "ValueAsString": null,
        "ValueAsBoolean": null,
        "ValueAsNumber": null,
        "ValueAsDecimal": null,
        "ValueAsDate": null,
        "ReferenceObject": null
      },
      "ReferenceObject": null
    },
    {
      "FieldId": 20,
      "ObjectId": 1,
      "DataTypeId": 1,
      "DataTypeName": "Basic Text",
      "Label": "Primary Phone",
      "IsRequired": false,
      "Position": 1,
      "Guid": 1500308933569,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": {
        "ObjectFieldValueId": 2166,
        "ObjectFieldId": 20,
        "ObjectId": 1,
        "PrimaryKeyId": 67,
        "ValueAsString": null,
        "ValueAsBoolean": null,
        "ValueAsNumber": null,
        "ValueAsDecimal": null,
        "ValueAsDate": null,
        "ReferenceObject": null
      },
      "ReferenceObject": null
    },
    {
      "FieldId": 21,
      "ObjectId": 1,
      "DataTypeId": 1,
      "DataTypeName": "Basic Text",
      "Label": "Primary Email",
      "IsRequired": false,
      "Position": 2,
      "Guid": 1500308948435,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": {
        "ObjectFieldValueId": 2167,
        "ObjectFieldId": 21,
        "ObjectId": 1,
        "PrimaryKeyId": 67,
        "ValueAsString": null,
        "ValueAsBoolean": null,
        "ValueAsNumber": null,
        "ValueAsDecimal": null,
        "ValueAsDate": null,
        "ReferenceObject": null
      },
      "ReferenceObject": null
    },
    {
      "FieldId": 27,
      "ObjectId": 1,
      "DataTypeId": 2,
      "DataTypeName": "Rich Text",
      "Label": "Notes and Misc.",
      "IsRequired": false,
      "Position": 4,
      "Guid": 1531172010609,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": {
        "ObjectFieldValueId": 2168,
        "ObjectFieldId": 27,
        "ObjectId": 1,
        "PrimaryKeyId": 67,
        "ValueAsString": null,
        "ValueAsBoolean": null,
        "ValueAsNumber": null,
        "ValueAsDecimal": null,
        "ValueAsDate": null,
        "ReferenceObject": null
      },
      "ReferenceObject": null
    },
    {
      "FieldId": 55,
      "ObjectId": 1,
      "DataTypeId": 10,
      "DataTypeName": "Reference",
      "Label": "User",
      "IsRequired": false,
      "Position": 5,
      "Guid": 2907893454017,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": {
        "ObjectFieldValueId": 2169,
        "ObjectFieldId": 55,
        "ObjectId": 1,
        "PrimaryKeyId": 67,
        "ValueAsString": null,
        "ValueAsBoolean": null,
        "ValueAsNumber": null,
        "ValueAsDecimal": null,
        "ValueAsDate": null,
        "ReferenceObject": {
          "ObjectFieldReferenceObjectInstanceId": 324,
          "ObjectFieldValueId": 2169,
          "ObjectId": 8,
          "Object": null,
          "PrimaryObjectId": 1,
          "PrimaryKeyId": 67,
          "KeyType": "String",
          "DisplayFormat": "%Val%",
          "IsSystemObject": true,
          "Name": null,
          "NumberOfValues": 0,
          "Values": []
        }
      },
      "ReferenceObject": null
    }
  ]
}


What's Next