PowerWebPart 2010

Oct 5, 2011 at 2:36 AM
Edited Dec 5, 2011 at 8:39 PM

I get basic ps code running in my webpart... I can query a list, foreach down it and even add new items to another list.  BUT, when I try to use spquery, I get a very odd syntax error.  Now, I know my loop is an empty loop, just to keep it simple.  I basically used your example to setup the form and button to execute the render. 

Error on event dispatcher 
PowerShell Exception:
The following exception was thrown when trying to enumerate the collection: "One or more field types are not installed properly. Go to the list settings page to delete these fields.".
At line:58 char:8 + foreach <<<< ($loan2 in $TLI) {}
at iLoveSharePoint.WebControls.PowerControl.Render(HtmlTextWriter writer) at iLoveSharePoint.WebControls.PowerWebPart.RenderContents-- sn(HtmlTextWriter writer)

-- code below --

## declare global variables and functions
$textbox = New-Object System.Web.UI.WebControls.TextBox
$button = New-Object System.Web.UI.WebControls.Button
$label = New-Object System.Web.UI.WebControls.Label
$spquery=New-Object Microsoft.SharePoint.SPQuery


-- snippet of render function --

function OnButtonClicked($sender, $args)

  $label.Text = "Processing Cash Receipts"


  foreach ($loan in $Loans.items) {

 $query="<Where><Eq><FieldRef Name='Loan' LookupId='TRUE'/><Value Type='Lookup'>"
 $query = $Query+ $Loan["ID"] + "</Value></Eq></Where>"

 $TLI = $Investors.GetItems($SPQuery)
$label.text = ">>" + $query

foreach ($loan2 in $TLI) {}

#  }
#   $label.Text = "Completed Cash Receipts"


--Update: The Crazy thing is if I put the exact code in a PS1 file and call THAT from PowerWebPart, it executes fine!