I try to set the value of an element. It it is not empty in my XML, it works, but if it is empty, is doesn't work.
My XML:
...
<Field IDREF="934d80f1" Name="FirstName">works</Field>
<Field IDREF="936845ba" Name="LastName"></Field>
...
If I write the contents with
$record.BusinessObject.FieldList.Field | Where-Object { $_.Name -eq $field }
it returns
IDREF Name #text
----- ---- -----
934d80f1 FirstName works
And in the second row the "virtual" Attribute #text is missing:
IDREF Name
----- ----
936845ba LastName
with the PowerShell code
record.BusinessObject.FieldList.Field | Where-Object { $_.Name -eq $field } | ForEach-Object { $_.'#text' = $state }
I want to set the value >VALUE< of the selected element. It doesn't work if the value is empty...
How can I do this?
Try using the $_.InnerXml property, and it will set the value on the required field.
$record.BusinessObject.FieldList.Field | Where-Object {
$_.Name -eq $field
} | ForEach-Object {
$_.InnerXml = $state
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With