Summary
Updates an existing form.
Set-Form
-EntryReturns a form object.
Parameters
Parameter | Type | Required? | Notes |
|---|---|---|---|
Entry | Form Object | Yes |
Examples
Updates an existing form
This example locates a field, makes it required, and adds a default value:
$ErrorActionPreference = 'Stop'
# Get the form
$form = Get-Form -Id 99
# Get the basic text field from the form
$myBasicTextField = $form.Sections |
ForEach-Object { $_.Fields } |
Where-Object { $_.Label -eq "My Basic Text Field" } |
Select-Object -First 1
if ($null -eq $myBasicTextField) {
Write-Error "Field 'My Basic Text Field' was not found on form #$($form.FormId)."
exit
}
# Make the field required and add a default value
$myBasicTextField.IsRequired = $true
$myBasicTextField.DefaultValue = "Placeholder value"
# Set-Form may report a serialization error. The form gets created, but the system chokes on
# returning the data back, so we need to work around that.
function Test-IsKnownODataNullSourceError {
param([Parameter(Mandatory)] [object]$ErrorRecord)
# Unwrap AggregateException if present
$ex = $ErrorRecord.Exception
if ($ex -is [System.AggregateException] -and $ex.InnerExceptions.Count -gt 0) {
$ex = $ex.InnerExceptions[0]
}
# Walk inner exceptions and look for the specific serialization error message
while ($null -ne $ex) {
if ($ex.Message -match "Value cannot be null\.\s*\(Parameter 'source'\)") {
return $true
}
$ex = $ex.InnerException
}
return $false
}
# Attempt update
try {
Set-Form -Entry $form -ErrorAction Stop | Out-Null
}
catch {
if (Test-IsKnownODataNullSourceError $_) {
if ($global:Error.Count -gt 0) { $global:Error.RemoveAt(0) }
$updated = $null
}
else {
throw
}
}
# Reload the form to review applied changes
$form = Get-Form -Id 99
Write-Output "Updated form '$($form.Name)' (Id: #$($form.formId), # of sections: $($form.NumberOfSections), # of fields: $($form.NumberOfFields))"
# For debug purposes, convert the entity to output as JSON so we can see the available fields
$jsonOutput = $form | ConvertTo-Json -Depth 10
Write-Output ""
Write-Output "JSON Results:"
# Output the JSON results
Write-Output $jsonOutputExecution results:
Updated form 'My Form' (Id: #99, # of sections: 1, # of fields: 10)
JSON Results:
{
"FormId": 99,
"FormTypeId": 1,
"FormType": null,
"FormTypeName": "Tasks",
"Name": "My Form",
"Category": "General",
"Description": null,
"IsAvailableOnPortal": false,
"NumberOfSections": 1,
"NumberOfFields": 10,
"CreatedByFullName": "Max Miller",
"CreatedById": "510e109b-6ff5-4442-9670-cd5e3cd82a7a",
"CreatedOn": "2026-01-21T13:07:18.6211605+00:00",
"CreatedBy": null,
"LastUpdatedByFullName": "Max Miller",
"LastUpdatedById": "510e109b-6ff5-4442-9670-cd5e3cd82a7a",
"LastUpdatedOn": "2026-01-21T14:03:42.5422495+00:00",
"LastUpdatedBy": null,
"Sections": [
{
"SectionId": 120,
"FormId": 99,
"Heading": "Section 1",
"Position": 0,
"Guid": 1148648158110,
"Fields": [
{
"FieldId": 475,
"SectionId": 120,
"DataTypeId": 1,
"DataTypeName": "Basic Text",
"Label": "My Basic Text Field",
"IsRequired": true,
"IsVisible": true,
"Position": 1,
"Guid": 4167049853533,
"DefaultValue": "Placeholder value",
"ReferenceObject": null,
"ConditionGroups": [],
"AppliedProperties": []
},
{
"FieldId": 476,
"SectionId": 120,
"DataTypeId": 2,
"DataTypeName": "Rich Text",
"Label": "My Rich Text Field",
"IsRequired": false,
"IsVisible": true,
"Position": 2,
"Guid": 6798658424189,
"DefaultValue": null,
"ReferenceObject": null,
"ConditionGroups": [],
"AppliedProperties": []
},
{
"FieldId": 477,
"SectionId": 120,
"DataTypeId": 3,
"DataTypeName": "Whole Number",
"Label": "My Whole Number Field",
"IsRequired": false,
"IsVisible": true,
"Position": 3,
"Guid": 5168576493377,
"DefaultValue": null,
"ReferenceObject": null,
"ConditionGroups": [],
"AppliedProperties": []
},
{
"FieldId": 478,
"SectionId": 120,
"DataTypeId": 4,
"DataTypeName": "Decimal Number",
"Label": "My Decimal Number Field",
"IsRequired": false,
"IsVisible": true,
"Position": 4,
"Guid": 9276055131768,
"DefaultValue": null,
"ReferenceObject": null,
"ConditionGroups": [],
"AppliedProperties": []
},
{
"FieldId": 479,
"SectionId": 120,
"DataTypeId": 5,
"DataTypeName": "Yes or No Choice",
"Label": "My Yes or No Field",
"IsRequired": false,
"IsVisible": true,
"Position": 5,
"Guid": 6772880977176,
"DefaultValue": null,
"ReferenceObject": null,
"ConditionGroups": [],
"AppliedProperties": []
},
{
"FieldId": 480,
"SectionId": 120,
"DataTypeId": 6,
"DataTypeName": "Date Only",
"Label": "My Date and Time Field",
"IsRequired": false,
"IsVisible": true,
"Position": 6,
"Guid": 287848767297,
"DefaultValue": null,
"ReferenceObject": null,
"ConditionGroups": [],
"AppliedProperties": []
},
{
"FieldId": 481,
"SectionId": 120,
"DataTypeId": 7,
"DataTypeName": "Date and Time",
"Label": "My Date Only Field",
"IsRequired": false,
"IsVisible": true,
"Position": 7,
"Guid": 7568294219059,
"DefaultValue": null,
"ReferenceObject": null,
"ConditionGroups": [],
"AppliedProperties": []
},
{
"FieldId": 482,
"SectionId": 120,
"DataTypeId": 8,
"DataTypeName": "Single Choice",
"Label": "My Single Choice Field",
"IsRequired": false,
"IsVisible": true,
"Position": 8,
"Guid": 5957387833874,
"DefaultValue": "Choice 1\nChoice 2\nChoice 3",
"ReferenceObject": null,
"ConditionGroups": [],
"AppliedProperties": []
},
{
"FieldId": 483,
"SectionId": 120,
"DataTypeId": 9,
"DataTypeName": "Multiple Choice",
"Label": "My Multiple Choice Field",
"IsRequired": false,
"IsVisible": true,
"Position": 9,
"Guid": 9747052228830,
"DefaultValue": "Item A\nItem B\nItem C",
"ReferenceObject": null,
"ConditionGroups": [],
"AppliedProperties": []
},
{
"FieldId": 484,
"SectionId": 120,
"DataTypeId": 10,
"DataTypeName": "Reference",
"Label": "My Contacts Reference Field",
"IsRequired": false,
"IsVisible": true,
"Position": 10,
"Guid": 1617698717842,
"DefaultValue": null,
"ReferenceObject": {
"FieldReferenceObjectId": 66,
"FieldId": 484,
"ObjectId": 7,
"Object": null,
"KeyType": "Int32",
"DisplayFormat": "%Val%",
"IsSystemObject": true,
"Name": "Contact",
"DefaultValues": []
},
"ConditionGroups": [],
"AppliedProperties": []
}
]
}
]
}