SharePoint 場所レコードに対するアクション

 

公開日: 2017年1月

対象: Dynamics 365 (online)、Dynamics 365 (on-premises)、Dynamics CRM 2016、Dynamics CRM Online

Microsoft Dynamics 365 SDK では、Microsoft SharePoint 場所レコードの以下のアクションを実行できます。

  • サイトの場所レコードの既定値としての設定

  • ドキュメントの場所レコードとエンティティ レコードの関連付け

  • 場所レコードの絶対 URL およびサイト コレクション URL の取得

場所レコードの作成、取得、更新、および削除

SharePointSite エンティティおよび SharePointDocumentLocation エンティティに Microsoft Dynamics 365 SDK のメッセージを使用して、レコードを作成、取得、更新、および削除できます。SharePointSite エンティティにこのような操作を実行するには、Microsoft Dynamics 365 のシステム管理者ロールが必要です。 サポートされているメッセージの一覧については、「SharePointSite エンティティ メッセージおよびメソッド」および「SharePointDocumentLocation エンティティ メッセージおよびメソッド」を参照してください。

注意

SharePoint の場所レコードに対してこれらの操作を実行しても、Microsoft Dynamics 365 でデータが処理されるだけです。SharePoint サーバーで場所の作成、更新、または削除が行われるわけではありません。

SharepointSite.ValidationStatus 属性は、SharePoint サイトの URL の検証ステータスを示します。検証の状態 (sharepoint_validationstatus) オプション セットで、この属性に指定できる値が定義されます。

SharepointSite.ValidationStatusErrorCode 属性は、SharePoint サイトの URL の検証ステータスの理由を示します。検証ステータス (sharepoint_validationstatusreason) オプション セットで、この属性に指定できる値が定義されます。

SharePoint Server サイト コレクションが複数のサイトを格納できるコンテナーであり、各サイトが複数のサイトまたはドキュメント ライブラリを含むことができる場合、SharePoint の保存場所は階層になっています。 各ドキュメント ライブラリは複数のドキュメント フォルダーを含むことができます。Microsoft Dynamics 365 で場所レコードを作成するとき、SharePoint Server 上のこれらの場所のパスまたは URL を指定します。

SharePoint の場所レコードの絶対 URL

これは、SharePoint 上の保存場所の完全な URL です。SharePointSite.AbsoluteURL または SharePointDocumentLocation.AbsoluteURL プロパティを使用して絶対 URL を指定できます。

絶対 URL を指定して SharePointSite のレコードを作成するには、次の手順に従います。


// Instantiate a SharePoint site object.
// See the Entity Metadata topic in the SDK documentation to determine 
// which attributes must be set for each entity.
SharePointSite spSite = new SharePointSite
{
    Name = "Sample SharePoint Site",
    Description = "Sample SharePoint Site Location record",

    // TODO: Change this URL to a valid SharePoint URL.                        
    AbsoluteURL = "http://www.example.com",
};

// Create a SharePoint site record named Sample SharePoint Site.
_spSiteId = _serviceProxy.Create(spSite);

' Instantiate a SharePoint site object.
' See the Entity Metadata topic in the SDK documentation to determine 
' which attributes must be set for each entity.
Dim spSite As SharePointSite =
 New SharePointSite With {
  .Name = "Sample SharePoint Site",
  .Description = "Sample SharePoint Site Location record",
  .AbsoluteURL = "http://www.example.com"
 }
' TODO: Change this URL to a valid SharePoint URL.                        

' Create a SharePoint site record named Sample SharePoint Site.
_spSiteId = _serviceProxy.Create(spSite)

同様に、SharePoint のドキュメントの場所レコードを作成するときも、次のように絶対 URL を指定します。

SharePointDocumentLocation spDocLoc = new SharePointDocumentLocation
{
    Name = "Sample SharePoint Document Location",
    Description = "Sample SharePoint Document Location record",
    AbsoluteUrl = "http://www.example.com/spdocloc"   
};
_spDocLocId = _serviceProxy.Create(spDocLoc);

通常、絶対 URL は SharePoint サイト レコードに対して指定します。これらはコンテナーすなわち親オブジェクトであり、その中にドキュメントを格納して管理するための他の場所を作成できるためです。

注意

SharePointDocumentLocation.LocationType 属性は、SharePointDocumentLocation レコードが SharePoint フォルダー(0) を指すか、または OneNote ファイル (1) を指すかを指定します。SharePointDocumentLocation インスタンス (レコード) を作成すると、SharePointDocumentLocation.LocationType 属性の値は既定で 0 に設定されて、SharePoint フォルダーを指していることを示します。 OneNote のサポートの詳細については、「Microsoft Dynamics 365 の OneNote との統合」を参照してください。

SharePoint の場所レコードの相対 URL

これは、SharePoint サーバーでの場所レコードの親場所レコードを基準とした相対的な位置です。SharePoint の場所レコードの相対 URL を指定するときは、作成場所の親オブジェクトも指定する必要があります。Microsoft Dynamics 365 はまず親オブジェクトの URL を使用して、子オブジェクトの絶対 URL を判断します。 たとえば、前の例で作成した SharePoint のサイトに SharePoint のドキュメントの場所レコードを作成するには、次のように指定する必要があります。


// Instantiate a SharePoint document location object.
// See the Entity Metadata topic in the SDK documentation to determine 
// which attributes must be set for each entity.
SharePointDocumentLocation spDocLoc = new SharePointDocumentLocation
{
    Name = "Sample SharePoint Document Location",
    Description = "Sample SharePoint Document Location record",

    // Set the Sample SharePoint Site created earlier as the parent site.
    ParentSiteOrLocation = new EntityReference(SharePointSite.EntityLogicalName, _spSiteId),
    RelativeUrl = "spdocloc",

    // Associate this document location instance with the Fourth Coffee
    // sample account record.
    RegardingObjectId = new EntityReference(Account.EntityLogicalName, _account1Id)
};

// Create a SharePoint document location record named Sample SharePoint Document Location.
_spDocLocId = _serviceProxy.Create(spDocLoc);

' Instantiate a SharePoint document location object.
' See the Entity Metadata topic in the SDK documentation to determine 
' which attributes must be set for each entity.
Dim spDocLoc As SharePointDocumentLocation =
 New SharePointDocumentLocation With {
  .Name = "Sample SharePoint Document Location",
  .Description = "Sample SharePoint Document Location record",
  .ParentSiteOrLocation = New EntityReference(SharePointSite.EntityLogicalName, _spSiteId),
  .RelativeUrl = "spdocloc",
  .RegardingObjectId = New EntityReference(Account.EntityLogicalName, _account1Id)
 }
' Set the Sample SharePoint Site created earlier as the parent site.
' Associate this document location instance with the Fourth Coffee
' sample account record.

' Create a SharePoint document location record named Sample SharePoint Document Location.
_spDocLocId = _serviceProxy.Create(spDocLoc)

下位のオブジェクト (この例でのドキュメントの場所) の絶対 URL は: “Parent_URL/Relative_URL” です。 したがって、この例ではドキュメントの場所の絶対 URL は http://www.example.com/spdocloc です。

通常、相対 URL を指定するのは、場所レコードを階層の下位に作成するとき、つまり子レコードとして作成するときです。

相対 URL を使用する利点は、ドキュメントを格納するために違う SharePoint サーバーに移ることを決めた場合に、Microsoft Dynamics 365 で親オブジェクトの場所レコード (おそらくサイト コレクションまたはサイト レコード) の絶対 URL を更新するだけで済むことです。また、絶対 URL (Microsoft Dynamics 365 によって自動的に決定される) は変わらないため、階層の下位にある他のすべてのレコードは前と同様に使用できます。 このような子場所レコードに対して絶対 URL を使用していた場合は、それぞれの URL を修正する必要があります。

サイトの場所レコードの既定値としての設定

SharePoint サイトの場所レコードを既定値として設定すると、Microsoft Dynamics 365 を使用して作成されるすべてのドキュメントの場所が、このサイトに自動的に作成されます。 サイトの場所レコードを既定値として作成するには、SharePointSite.IsDefault プロパティを true に設定します。 サイトの場所レコードを作成または更新するときに、サイトの場所レコードを既定値として設定できます。

注意

ドキュメントの場所レコードの自動作成が可能なのは、ターゲット サイトが SharePoint 2010 またはSharePoint 2013 サーバーであり、SharePoint Server 用 Microsoft Dynamics CRM リスト コンポーネント がターゲットの SharePoint サイト コレクションにインストールされている場合のみです。Microsoft Dynamics CRM リスト コンポーネント の詳細については、「Microsoft SharePoint Server 用Microsoft Dynamics CRM list component」を参照してください。

ドキュメントの場所レコードとエンティティ レコードの関連付け

ドキュメントの場所レコードをエンティティ レコードに関連付けることができます。 関連付けを行うと、エンティティ レコードのすべてのドキュメントが SharePoint サーバーのこの場所に格納されます。SharePointDocumentLocation.RegardingObjectId プロパティを使用して、SharePoint ドキュメントの場所レコードをエンティティに関連付けることができます。 以下のサンプルは、その方法を示しています。


// Instantiate a SharePoint document location object.
// See the Entity Metadata topic in the SDK documentation to determine 
// which attributes must be set for each entity.
SharePointDocumentLocation spDocLoc = new SharePointDocumentLocation
{
    Name = "Sample SharePoint Document Location",
    Description = "Sample SharePoint Document Location record",

    // Set the Sample SharePoint Site created earlier as the parent site.
    ParentSiteOrLocation = new EntityReference(SharePointSite.EntityLogicalName, _spSiteId),
    RelativeUrl = "spdocloc",

    // Associate this document location instance with the Fourth Coffee
    // sample account record.
    RegardingObjectId = new EntityReference(Account.EntityLogicalName, _account1Id)
};

// Create a SharePoint document location record named Sample SharePoint Document Location.
_spDocLocId = _serviceProxy.Create(spDocLoc);

' Instantiate a SharePoint document location object.
' See the Entity Metadata topic in the SDK documentation to determine 
' which attributes must be set for each entity.
Dim spDocLoc As SharePointDocumentLocation =
 New SharePointDocumentLocation With {
  .Name = "Sample SharePoint Document Location",
  .Description = "Sample SharePoint Document Location record",
  .ParentSiteOrLocation = New EntityReference(SharePointSite.EntityLogicalName, _spSiteId),
  .RelativeUrl = "spdocloc",
  .RegardingObjectId = New EntityReference(Account.EntityLogicalName, _account1Id)
 }
' Set the Sample SharePoint Site created earlier as the parent site.
' Associate this document location instance with the Fourth Coffee
' sample account record.

' Create a SharePoint document location record named Sample SharePoint Document Location.
_spDocLocId = _serviceProxy.Create(spDocLoc)

場所レコードの絶対 URL およびサイト コレクション URL の取得

前に説明したように、SharePoint Server は階層モデルでレコードを格納します。 階層内の場所レコードの絶対 (完全) URL と、その場所レコードが存在する SiteCollection URL を取得する場合は、RetrieveAbsoluteAndSiteCollectionUrlRequest メッセージを使用できます。

RetrieveAbsoluteAndSiteCollectionUrlRequest メッセージが正常に機能するのは、次の 2 つに該当する場合のみです。

  • SharePoint Server 用 Microsoft Dynamics CRM リスト コンポーネント が、ターゲット SharePoint 2010 または SharePoint 2013サーバーの SharePoint サイト コレクションにインストールされています。 詳細については、「Microsoft SharePoint Server 用Microsoft Dynamics CRM list component」を参照してください。

  • 親 SharePoint サイトコレクションの場所レコードが Microsoft Dynamics 365 に存在しており、親場所レコードの作成時に SharePointSite.IsGridPresent プロパティが true に設定されています。

これらの条件を満たさない場合は、SiteCollectionUrl プロパティの空の値または正しくない値が得られます。

詳細については、「RetrieveAbsoluteAndSiteCollectionUrlRequest」を参照してください。

次のサンプルは、RetrieveAbsoluteAndSiteCollectionUrl メッセージの使用方法を示します。


// Retrieve the absolute URL and the Site Collection URL
// of the SharePoint document location record.
RetrieveAbsoluteAndSiteCollectionUrlRequest retrieveRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest
{
    Target = new EntityReference(SharePointDocumentLocation.EntityLogicalName, _spDocLocId)
};
RetrieveAbsoluteAndSiteCollectionUrlResponse retriveResponse = (RetrieveAbsoluteAndSiteCollectionUrlResponse)_serviceProxy.Execute(retrieveRequest);

Console.WriteLine("Absolute URL of document location record is '{0}'.", retriveResponse.AbsoluteUrl.ToString());
Console.WriteLine("Site Collection URL of document location record is '{0}'.", retriveResponse.SiteCollectionUrl.ToString());

' Retrieve the absolute URL and the Site Collection URL
' of the SharePoint document location record.
Dim retrieveRequest As RetrieveAbsoluteAndSiteCollectionUrlRequest =
 New RetrieveAbsoluteAndSiteCollectionUrlRequest With {
  .Target = New EntityReference(SharePointDocumentLocation.EntityLogicalName, _spDocLocId)
 }
Dim retriveResponse As RetrieveAbsoluteAndSiteCollectionUrlResponse =
 CType(_serviceProxy.Execute(retrieveRequest), RetrieveAbsoluteAndSiteCollectionUrlResponse)

Console.WriteLine("Absolute URL of document location record is '{0}'.", retriveResponse.AbsoluteUrl.ToString())
Console.WriteLine("Site Collection URL of document location record is '{0}'.", retriveResponse.SiteCollectionUrl.ToString())

関連項目

RetrieveAbsoluteAndSiteCollectionUrlRequest
RetrieveAbsoluteAndSiteCollectionUrlResponse
Microsoft Dynamics 365 を SharePoint と統合
SharePoint 統合に関する入門情報
エンティティのドキュメント管理を有効にする
SharePoint 統合エンティティ
サンプル: エンティティに対するドキュメント管理を有効にする
サンプル: SharePoint 場所レコードの作成、取得、更新、および削除
サンプル: 場所レコードの絶対 URL およびサイト コレクション URL の取得
Microsoft Dynamics 365 の OneNote との統合

Microsoft Dynamics 365

© 2017 Microsoft. All rights reserved. 著作権