1

I am trying to edit an item of template type /sitecore/templates/System/Forms/Fields/Input. This item has a field named Default Value.

Why does this work:

$DefaultValueFieldName = "Default Value"
$myInputFieldItem.Editing.BeginEdit()
$myInputFieldItem[$DefaultValueFieldName] = "some value"

But this doesn't update the field?

$myInputFieldItem.$DefaultValueFieldName = "some value"

In addition, I get this error:

ERROR: The property 'Default Value' cannot be found on this object. Verify that the property exists and can be set. 
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

In fact, none of these other variations work either:

$myInputFieldItem."Default Value"= "some value"
$myInputFieldItem."Title"= "some value"
$myInputFieldItem."Css Class"= "some value"

Note that I CAN use this notation to edit other items successfully; just not in this case with this specific template type.

I am running the script as an administrator.

The software versions are:

  • Sitecore PowerShell Extensions 5.1.0.19766
  • Sitecore 9.0 Windows
  • PowerShell 5.1
6
  • $myInputFieldItem.Editing.BeginEdit() are you using this one in all cases ? what user do you use when you run the script ? Feb 20 at 16:04
  • I am not using .Editing.BeginEdit() in all cases because it's not required when doing direct field edits (e.g. $myItem.MyField = "some val"). I am running as admin. Feb 20 at 16:28
  • Can you explain how its "not working" - as in, does it show an error message? Is there anything in the logs you can see? Is the field just not updated? Also, is the item protected?
    – Richard Seal
    Feb 20 at 17:15
  • @RichardSeal I updated the question with the info: the field does not update and SPE throws that exception. I don't see any errors in the Sitecore logs. Feb 20 at 18:38
  • Are you running as Administrator? or from any other role? Feb 21 at 9:28

1 Answer 1

1

I don't know how the field item is retrieved in your PowerShell script, but I had this error when an item was read using Sitecore API and was not wrapped with automatic SPE properties using Initialize-Item:

The Initialize-Item command wraps Sitecore item with PowerShell property equivalents of fields for easy assignment of values to fields and automatic saving. This command can also be used to translate the the Sitecore.ContentSearch.SearchTypes.SearchResultItem items obtained from the Find-Item command into full Sitecore Items. The alias for the command is Wrap-Item.

See examples below.

This works:

$DefaultValueFieldName = "Default Value"
$myInputFieldItem = Get-Item -Path "master:/sitecore/Forms/Test form/Page/Firstname"
$myInputFieldItem.$DefaultValueFieldName = "some value"

This doesn't work and throws the error The property 'Default Value' cannot be found on this object. Verify that the property exists and can be set. because $myInputFieldRawItem does not have automatic properties:

$DefaultValueFieldName = "Default Value"
$myInputFieldRawItem = [Sitecore.Configuration.Factory]::GetDatabase("master").GetItem("/sitecore/Forms/Test form/Page/Firstname")
$myInputFieldRawItem.$DefaultValueFieldName = "some value"

But this works:

$DefaultValueFieldName = "Default Value"
$myInputFieldRawItem = [Sitecore.Configuration.Factory]::GetDatabase("master").GetItem("/sitecore/Forms/Test form/Page/Firstname")
$myInputFieldItem = $myInputFieldRawItem | Initialize-Item
$myInputFieldItem.$DefaultValueFieldName = "some value"
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.