javascript - 从 Sharepoint 2013 中的另一个列表获取 Peoplepicker 字段的详细信息

标签 javascript sharepoint-2013

我在客户表单中有一项功能,如果我选择资源名称(人员选择器列)、剩余的 EmpID、 必须填写“项目”和“经理”列。所有这些列都位于名为“EmpDetails”的列表中。 我尝试使用 CAML 查询但未能成功。这是我的代码:

<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 初学者,从某个网站获取了上述代码。我不知道这是否是正确的代码。请帮忙。

最佳答案

您的 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 ;>

关于javascript - 从 Sharepoint 2013 中的另一个列表获取 Peoplepicker 字段的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44280489/

相关文章:

iphone - 如何将 iOS 11 应用程序与本地 SharePoint 2013 连接

javascript - 通过designer 2013添加js以删除sharepoint上的功能区

javascript - 如何在元素外添加点击事件?

javascript - knockout foreach 中的自定义绑定(bind)以获取迭代器

javascript - 添加溢出 : scroll only when the window size is 1366 * 768 and below

javascript - 使用javascript修改SharePoint 2013列表列标题

windows-phone-8 - Visual Studio 2013 Professional 的 Sharepoint Phone SDK 安装

c# - 如何获取名称和ID是动态的表单字段的值

javascript - 如果使用 prev() 找到序列则添加类

javascript - microsoft Dynamics crm 2015 JavaScript 字符串连接错误