2009-08-17 12 views
2

SharePointサーバーを使用していて、プログラムのリクエストをマイクロソフトのコールセンターアプリケーションテンプレートにプログラムで追加しようとしています。これまでのところ、私はかなり良い成功を収めました。私は、指定された顧客のための呼び出しを追加し、特定のサポート技術を割り当てることができます。SharePointフィールドの選択欄からすべてのアイテムを取得する

private enum FieldNames 
{ 
    [EnumExtension.Value("Service Request")] 
    ServiceRequest, 
    [EnumExtension.Value("Customer")] 
    Customer, 
    [EnumExtension.Value("Service Representative")] 
    ServiceRepresentative, 
    [EnumExtension.Value("Assigned To")] 
    AssignedTo, 
    [EnumExtension.Value("Software")] 
    Software, 
    [EnumExtension.Value("Category")] 
    Category 
} 
private void CreateServiceCall(string serviceCallTitle, string customerName, string serviceRep) 
{ 
    SPSite allSites = new SPSite(siteURL); 
    SPWeb site = allSites.AllWebs[siteName]; 
    SPListItemCollection requestsList = site.Lists[serviceRequests].Items; 
    SPListItem item = requestsList.Add(); 

    SPFieldLookup customerLookup = item.Fields[FieldNames.Customer.Value()] as SPFieldLookup; 

    item[FieldNames.ServiceRequest.Value()] = serviceCallTitle; 

    if (customerLookup != null) 
    { 
     using (SPWeb lookupWeb = allSites.OpenWeb(customerLookup.LookupWebId)) 
     { 
      SPList lookupList = lookupWeb.Lists.GetList(new Guid(customerLookup.LookupList), false); 
      foreach (SPListItem listItem in lookupList.Items) 
      { 
       if (listItem[customerLookup.LookupField].ToString() != customerName) continue; 

       item[FieldNames.Customer.Value()] = new SPFieldLookupValue(listItem.ID, customerName); 
       break; 
      } 
     } 
    } 
    SPUserCollection userCollection = site.SiteUsers; 
    if (userCollection != null) 
    { 
     foreach (SPUser user in userCollection) 
     { 
      if (user.Name != serviceRep) continue; 

      item[FieldNames.AssignedTo.Value()] = user; 
      break; 
     } 
    } 

    item.Update(); 

    site.Close(); 
    allSites.Close(); 
} 

私はデフォルトのリストには、2つのカスタム列(カテゴリ、ソフトウェア)を追加しました:私は両方の人口

alt text

をSharePoint内のこれらの列のうち、そのデータを取得したいので、適切なカテゴリ/ソフトウェアなどを呼び出すために投稿したコードスニペットで使用できます。コードでリストを取得できませんでしたが、item["Software"],site.Lists["Software"]などを使用して試しましたが、これまでのところすべてがnullです。

誰も私にこの方向性を向けることができますか?ありがとう!あなたは、フィールド上の値を設定する必要がある場合

SPFieldMultiChoice software = item.Fields[FieldNames.Software.Value()] as SPFieldMultiChoice; 
StringCollection softwareChoices = software.Choices; 

は、SPFieldMultiChoiceValueタイプを使用します:

答えて

8

SPFieldMultiChoiceおよび関連分野はChoices性質を持っている

SPFieldMultiChoiceValue values = new SPFieldMultiChoiceValue(); 
values.Add("Choice 1"); 
values.Add("Choice 2"); 
item[FieldNames.Software.Value()] = values; 
+0

完璧な、ありがとう! – Anders

+1

この例は 'SPListItem'から' SPFieldMultiChoice'オブジェクトを取得する方法を示しています - あなたが 'SPList'からこのオブジェクトを取得できることに注意してください。リストを取得した後にChoicesプロパティにアクセスしたいので、私がListの項目を反復する前に、 例では 'item.Fields'がアクセスされているのとまったく同じ方法で' SPList.Fields'プロパティにアクセスしてください。 – CBono

関連する問題