2017-05-31 106 views
1

如果我選擇一個資源名稱(人員選擇器列),那麼剩餘的EmpID 項目和經理列必須填寫。所有這些列都在名爲「EmpDetails」的列表中。 我嘗試使用CAML查詢,但無法成功。這是我的代碼:從Sharepoint 2013中的其他列表中獲取Peoplepicker字段的詳細信息

<tr class="container"> 
<div id="container"> 
    <table id="table"> 
     <thead> 
     <tr> 
      <th>Resource Name</th> 
      <th>EmpID</th> 
      <th>Projects</th> 
      <th>Manager</th> 
      <th></th> 
      <th></th> 
     </tr> 
     </thead> 
     <tbody> 
     <tr> 
      <td><span id="resourcename"></span></td> 
      <td><input type="text" id="txtempid" placeholder="Emp ID"/></td> 
      <td><input type="text" id="txtprojects" placeholder="Projects"/></td> 
      <td><input type="text" id="txtreportmgr" placeholder="Reporting Manager"/></td> 
      <td><input type="button" id="delrow" value="-" onclick="deleteRow(this)"/> </td> 
      <td><input type="button" id="addrow" value="+" onclick="addRow()"/> </td> 
     </tr> 
     </tbody> 
    </table> 
</div> 
</tr> 

Javascript代碼:

$(document).ready(function() { 
     ConvertoToRequestPeoplePicker('resourcename'); 
     BindData(); 


    }); 
    function BindData() 
{ 
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() { 
     context = new SP.ClientContext.get_current(); 
     LoadingMessage(); 
     SPLoaded(); 
    }); 
} 
function SPLoaded() 
{ 
try 
{ 
    var resourceInfoList = context.get_web().get_lists().getByTitle('EmpDetails'); 
    var resourceInfoQuery = new SP.CamlQuery(); 
    resourceInfoQuery.set_viewXml( '<View>' + 
             '<ViewFields>' + 
              '<FieldRef Name=\'EmpID\' />' + 
              '<FieldRef Name=\'Projects\' />' + 
              '<FieldRef Name=\'Manager\' />' + 
             '</ViewFields>' + 
             '<Query>' + 
              '<Where>' + 
               '<Value Type="User">' + itm.get_item("Employee").get_lookupId() + '</Value>'+ 
              '</Where>' + 
              '<OrderBy>' + 
               '<FieldRef Name="Title" Ascending="TRUE" />' + 
              '</OrderBy>' + 
             '</Query>' + 
            '</View>'); 
    var resourceInfoListItems = resourceInfoList.getItems(resourceInfoQuery); 
    context.load(resourceInfoListItems); 
    context.executeQueryAsync(Function.createDelegate(null, LoadConfigurationValues), Function.createDelegate(this, function (sender, arg) { alert("Error in getLoginUser : " + arg.get_message()); waitDialogLoad.close(SP.UI.DialogResult.OK); })); 

} 
    catch(ex) 
    { 
     alert("Something went wrong : "+ex.message); 
     waitDialogLoad.close(SP.UI.DialogResult.OK); 
    } 
} 

我在SharePoint初學者和有一些網站上面的代碼。我不知道這是否是正確的代碼或否。請幫忙。

回答

0

看來你的CAML查詢無效... 這樣的查詢的「Where'部分必須形成這樣的:

<Where> 
    <compareOperator> 
     <Value/> 
     <FieldRef/> 
    </compareOperator> 
</Where> 

的compareOperator通常是這樣的‘EQ’ ,「Lt」等。 該值通常會得到一個類型屬性,並且fieldref將定義列表(或庫)中的哪個字段應與查詢中的值進行比較。

把所有我們一起得到這樣一個例子:

<View> 
    <Query> 
     <Where> 
      <Geq> 
       <FieldRef Name='ID'/> 
       <Value Type='Number'>1</Value>/Geq> 
     </Where> 
    </Query> 
</View> 

爲了更深入瞭解,您可以檢查出sp jsom how-to;>

相關問題