Friday, November 13, 2015

Export Business Connectivity Model for External Content Types

Requirement: Export the content type of a web in SharePoint into an XML file so that it can be imported in other environments such as Test, Stage, and Production

Solution: Automate the export process of content type from SharePoint web using PowerShell script.

Script:
####################### ENVIRONMENT VARIABLES #######################  
 $SiteUrl= "http://app"  
 #####################################################################  
 $model = Get-SPBusinessDataCatalogMetadataObject -BdcObjectType "Model" -Name "BCSReferenceDataModel" -ServiceContext $SiteUrl  
 Import-SPBusinessDataCatalogModel -Path "C:\ BCSReferenceDataModel.bdcm" -Identity $model  

Import BCS Model for External Content Types

Requirement: Import business connectivity model (.bdcm) into SharePoint

Solution: Automate the import process of business connectivity model with PowerShell Script.

Script:

####################### ENVIRONMENT VARIABLES #######################


$SiteUrl= "http://app"

#####################################################################


$Catalog = Get-SPBusinessDataCatalogMetadataObject -BdcObjectType "Catalog" -Name "BCSReferenceDataModel" -ServiceContext $SiteUrl
echo $model

Write-Host "Importing BCS Modal..."

Import-SPBusinessDataCatalogModel -Identity $Catalog -Path "C:\BCSReferenceDataModel.bdcm" -force -ModelsIncluded -PropertiesIncluded -PermissionsIncluded -Verbose -ErrorAction Stop -ErrorVariable $err


The shim execution failed unexpectedly - Assembly was requested for LobSystem with Name

Error:
Microsoft.BusinessData.Infrastructure.BdcException: The shim execution failed unexpectedly - Assembly was requested for LobSystem with Name


Solution:
Import SPBusinessDataCatalogDotNetAssembly with the path and Lobsystem name (if you use BCSMetaman to geterate model, you can find this name in .bcsmm, otherwise you will have to look into your .bdcm file).

Script:

$url = "http://app"

# You could change the below to c drive like C:\BCSModel.dll for simple path
$assemblyPath = "C:\Windows\assembly\GAC_MSIL\BCSModel.dll\1.0.0.0__146767669ea2f41\BCSModel.dll" $lobSystem = "IPM.BCS.ReferenceData"

Write-Host "Adding assembly to LOBSystem"
$serviceContext = Get-SPServiceContext $url
$lobSystem = Get-SPBusinessDataCatalogMetadataObject -ServiceContext $serviceContext -BdcObjectType lobsystem -Name $lobSystem
Import-SPBusinessDataCatalogDotNetAssembly -LobSystem $lobSystem -Path $assemblyPath -Confirm:$false

Write-Host "Completed"


Export Content Type using PowerShell in SharePoint

Requirement: Export the content type of a web in SharePoint into an XML file so that it can be imported in other environments such as Test, Stage, and Production

Solution: Automate the export process of content type from SharePoint web using PowerShell script.

Script:

clear  
 Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue  
 Add-PSSnapin Microsoft.SharePoint.Powershell  
 ####################### ENVIRONMENT VARIABLES #######################  
 $contentTypeSourceWeb = "<<weburl>>" #Ex: http://webapp/sites/myproject  
 # This is the place where exported content type is stored the XML file  
 $xmlFilePathForContentType = "C:\Script-SiteContentTypes.xml"  
 #####################################################################  
 #Content Type group you are looking to export  
 $contentTypeGroupName = "Custom Content Types"  
 $sourceWeb = Get-SPWeb $contentTypeSourceWeb  
 #Create Export File  
 New-Item $xmlFilePathForContentType -type file -force  
 #Export Content Types to XML file  
 Add-Content $xmlFilePathForContentType "<?xml version=`"1.0`" encoding=`"utf-8`"?>"  
 Add-Content $xmlFilePathForContentType "`n<ContentTypes>"  
 $sourceWeb.ContentTypes | ForEach-Object {  
   if ($_.Group -eq $contentTypeGroupName) {  
     write-host "Adding content type to file."  
     Add-Content $xmlFilePathForContentType $_.SchemaXml  
   }  
 }  
 Add-Content $xmlFilePathForContentType "</ContentTypes>"  
 $sourceWeb.Dispose()  
 write-host "Completed"  

Access to XMLHttpRequest at 'from origin has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. .net core angular

Issue: The angular application was getting error from API that the origin has been blocked by CORS policy. Solution: Make sure that the...