Domanda

My problem is when copying items from a list to another, i can see the BCS field in the Display form(the value of the BCS in the display form is correct) but not in the Edit form(the text box of the BCS in the Edit form is empty).

here is my code :

$web = Get-SPWeb http://intranet/sales/
$listSales = $web.Lists["Sales Projects"]


$Prospect = Get-SPWeb http://intranet/CAC/
$listProspect = $Prospect.Lists["Clients"]


foreach ($item in $listSales.Items | Where {$_["Status"] -eq "Confirmed" -and $_["isDone"] -eq $null}) { 

Write-Host $item.Title

  $newItem = $listProspect.Items.Add();


  $newItem["Client's Name"] = $item["Client Name"]
  $newItem["Initiator"] = $item["Initiator"]
  #Depo is the external data Field (BCS).
  $newItem["Depositary"] = $item["Depo"]


  $newItem.Update()


  $item["isDone"]="Done"
  $item.Update()

}

È stato utile?

Soluzione

The solution is :

$web = Get-SPWeb http://intranet/sales/
$listSales = $web.Lists["Sales Projects"]


$Prospect = Get-SPWeb http://intranet/CAC/
$listProspect = $Prospect.Lists["Clients"]


foreach ($item in $listSales.Items | Where {$_["Status"] -eq "Confirmed" -and $_["isDone"] -eq $null}) { 

Write-Host $item.Title

$newItem = $listProspect.Items.Add();


$newItem["Client's Name"] = $item["Client Name"]
$newItem["Initiator"] = $item["Initiator"]


      #Get the BCS column as a BCS field for the item
      $Depo = $item.fields | ? {$_.Title -eq "Custodian / Depository"} 
      #Get the related ID field name
      $DepoBCSIDfield = $Depo.relatedfield

      $BCSID = $item[$Depo.relatedfield].tostring()
      $value = [Microsoft.SharePoint.BusinessData.Infrastructure.EntityInstanceIdEncoder]::DecodeEntityInstanceId($BCSID)


      $newDepo = $newItem.fields | ? {$_.Title -eq "Depository"} 
      $newDepoBCSID = $newDepo.relatedField
      $newItem[$newDepo.Title] = $item["Custodian / Depository"]
      $newItem[$newDepoBCSID] = $value

 $newItem.Update()


 $item["isDone"]="Done"
 $item.Update()
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top