Reputation: 1
I consider myself fairly new to scripting in PowerShell and I am currently having issues assigning the return value of an API request to a Data Row.
The returned value appears to be a custom object: <APITenant>.FRSHEATServiceReqTemplateParam
and if I try to assign this to the data table, it simply displays the object name rather than the values e.g.
Name Params
---- ------
Access to Mailbox/Distribution Group OscarStg.FRSHEATServiceReqTemplateParam[]
strSubscriptionRecId : 0221877CF3474492B8ACD9F7C0D94E4A
strDateSubscribed : 10/6/2017 8:09:58 AM
strOrgUnitId : 37393D7C9B554ACEB1F2F2505BA1FF6D
strName : Access to Mailbox/Distribution Group
strItem :
strDescription : Request for access to be added or removed from a
mailbox/group.
strServiceName : Email Messaging Service
strRecId : 21BB52854D524958A5C9F9E0DCAB60CB
lstParameters : {eacc_dpmnt, eacc_req, eacc_reqEmail, eacc_item...}
Can I assign the actual value to the data table?
EDIT:
$cboTmpl.Add_SelectedIndexChanged({
$tmplRecId = $cboTmpl.SelectedItem["RecId"]
$index = $dTblTmpl.RecId.IndexOf($cboTmpl.SelectedValue)
If($dTblTmpl.Rows[$index].SubId.GetTypeCode() -eq 'DBNull'){
$tmpSubName = $dTblTmpl.Rows[$index].Name.Replace("&", "&")
$dTblTmpl.Rows[$index].SubId = ($Oscar.GetSubscriptionId($connect.sessionKey, `
$txtTenant.Text, $tmpSubName)).subscriptionId
}
If($dTblTmpl.Rows[$index].Params.GetTypeCode() -eq 'DBNull'){
$currParams = ($Oscar.GetPackageData($connect.sessionKey, $txtTenant.Text, $dTblTmpl.Rows[$index].SubId)).srSubscription.lstParameters
$dTblTmpl.Rows[$index].Params = $currParams
}
})
The last if block calls the method and assigns this to the data table. I tried to use -ExpandProperty but it similarly assigns the string 'System.Object[]' as the value.
Do I need to explicitly define the column object?
Upvotes: 0
Views: 994
Reputation: 1
Got this working - I had to explicitly define the column as the base type of the object. In this case, [System.Array]
.
New-Variable -Name "$('col' + $Header)" -Value (New-Object `
System.Data.DataColumn $Header,([System.Array])) -Force}
Now it returns the proper value.
$dTblTmpl.Rows[2] | select Name, Params
Name Params
---- ------
[TEST] Request {chk, qty}
Upvotes: 0