簡體   English   中英

SharePoint JavaScript 顯示來自查找字段的值

[英]SharePoint JavaScript Display Value from Lookup Field

Existing system has HTML, JavaScript forms with the following: SharePoint List, "CustomerType" with values SharePoint List, "Customer" with lookup column named, "CustomerType" pulling values from "CustomerType"

需要添加一個新字段,所以我通過創建鏡像“CustomerType”:SharePoint 列表,“CustomerSegmentation”,值為 SharePoint 列表,“客戶”,查找列名為“CustomerSegmentation”,從“CustomerSegmentation”中提取值

我復制了 HTML、JavaScript 等 - 在“客戶”列表中選擇一個值和創建項目都很好。 但是,當我嘗試在“顯示”HTML 表單上顯示所選值時,使用:

                    var CustomerSegmentationField = oListItem.get_item('CustomerSegmentationField');
            if (checkNotEmpty(CustomerSegmentationField)) {
                $("#selCustomerSegmentationField").val(CustomerSegmentationField.get_lookupId());
            }

我收到此錯誤:未捕獲錯誤:屬性或字段尚未初始化。 它尚未被請求或請求尚未執行。 可能需要明確要求。 at Function.Error.create (ScriptResource.axd?d=k5RfMmPNK2hWIceXJ8-ajx3E8J_9Fwh_cmdsa2b8w5b_6SdxoV5CP7PTQYU2geZFptqlColfo4USOXQsdBih3W0VS_49yn_5vEAL69UdI91yC-tDiYJ5qy_HJzfGk6ituovIGh_kYQ43NWRInP8bleYrT4aM9uWrD_zUrKaOdVSegfYI0_gHDDpmP74zGEwh0&t=ffffffffecf19baa&ctag=200622:formatted:177) at SP.ListItem.$1D_2 (sp.js:formatted:15164) at SP.ListItem.get_item ( sp.js:formatted:14868) 在 onQuerySucceeded (Display-New-Request.aspx?itemID=9076:1678) 在陣列。 (ScriptResource.axd?d=k5RfMmPNK2hWIceXJ8-ajx3E8J_9Fwh_cmdsa2b8w5b_6SdxoV5CP7PTQYU2geZFptqlColfo4USOXQsdBih3W0VS_49yn_5vEAL69UdI91yC-tDiYJ5qy_HJzfGk6ituovIGh_kYQ43NWRInP8bleYrT4aM9uWrD_zUrKaOdVSegfYI0_gHDDpmP74zGEwh0&t=ffffffffecf19baa&ctag=200622:formatted:23) at ScriptResource.axd?d=k5RfMmPNK2hWIceXJ8-ajx3E8J_9Fwh_cmdsa2b8w5b_6SdxoV5CP7PTQYU2geZFptqlColfo4USOXQsdBih3W0VS_49yn_5vEAL69UdI91yC-tDiYJ5qy_HJzfGk6ituovIGh_kYQ43NWRInP8bleYrT4aM9uWrD_zUrKaOdVSegfYI0_gHDDpmP74zGEwh0&t=ffffffffecf19baa&ctag=200622:formatted:2555 at SP.ClientRequest.$3K_0 (sp .runtime.js:2) 在數組中。 (ScriptResource.axd?d=k5RfMmPNK2hWIceXJ8-ajx3E8J_9Fwh_cmdsa2b8w5b_6SdxoV5CP7PTQYU2geZFptqlColfo4USOXQsdBih3W0VS_49yn_5vEAL69UdI91yC-tDiYJ5qy_HJzfGk6ituovIGh_kYQ43NWRInP8bleYrT4aM9uWrD_zUrKaOdVSegfYI0_gHDDpmP74zGEwh0&t=ffffffffecf19baa&ctag=200622:formatted:23) at ScriptResource.axd?d=k5RfMmPNK2hWIceXJ8-ajx3E8J_9Fwh_cmdsa2b8w5b_6SdxoV5CP7PTQYU2geZFptqlColfo4USOXQsdBih3W0VS_49yn_5vEAL69UdI91yC-tDiYJ5qy_HJzfGk6ituovIGh_kYQ43NWRInP8bleYrT4aM9uWrD_zUrKaOdVSegfYI0_gHDDpmP74zGEwh0&t=ffffffffecf19baa&ctag=200622:formatted:2555 at Sys.Net.WebRequest.completed ( ScriptResource.axd?d=k5RfMmPNK2hWIceXJ8-ajx3E8J_9Fwh_cmdsa2b8w5b_6SdxoV5CP7PTQYU2geZFptqlColfo4USOXQsdBih3W0VS_49yn_5vEAL69UdI91yC-tDiYJ5qy_HJzfGk6ituovIGh_kYQ43NWRInP8bleYrT4aM9uWrD_zUrKaOdVSegfYI0_gHDDpmP74zGEwh0&t=ffffffffecf19baa&ctag=200622:formatted:4336)

我將非常感謝您的幫助-謝謝!

<script>
    function retrieveListItems(ID) {

        var clientContext = new SP.ClientContext("https://xxxxxxx/DIG/Customer/");
        var oList = clientContext.get_web().get_lists().getByTitle('Customer');
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml("<View>\
                                    <Query>\
                                       <Where>\
                                          <Eq>\
                                             <FieldRef Name='ID' />\
                                             <Value Type='Counter'>"+ ID +   
"</Value>\
                                          </Eq>\
                                       </Where>\
                                    </Query>\
                                  </View>");
        this.collListItem = oList.getItems(camlQuery);

        clientContext.load(collListItem);

        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

    }

    function onQuerySucceeded(sender, args) {
        var listItemEnumerator = collListItem.getEnumerator();
        while (listItemEnumerator.moveNext()) {
            var color = new Object();
            var oListItem = listItemEnumerator.get_current();
            // Add Section wise set items here.

            // Section 1
            $("#selRequestType").val(oListItem.get_item('RequestType'));
            
$("#txtCustomerNumber").val(oListItem.get_item('CustomerNumber'));
            var salesCont = (oListItem.get_item('ArdentSalesContact')).get_lookupValue();
            $("#txtArdentSalesContact").val(salesCont);
            var csr = (oListItem.get_item('CSR')).get_lookupValue();
            $("#txtCSR").val(csr);
            
$("#txtAdditionalComments").val(oListItem.get_item('AdditionalComments'));
            var company = oListItem.get_item('Company');
            var companyArray = company.split('~');
            for (var i = 0 ; i < companyArray.length; i++) {
                $.each($("input[name='company']"), function () {
                    if ($(this).val() == companyArray[i]) {
                        $(this).prop('checked', true);
                    }
                });
            }
            var OrderSystem = oListItem.get_item('OrderSystem');
            OrderSystemArray = OrderSystem.split('~');
            for (var i = 0 ; i < OrderSystemArray.length; i++) {
                $.each($("input[name='OrderSystem']"), function () {
                    if ($(this).val() == OrderSystemArray[i]) {
                        $(this).prop('checked', true);
                    }
                });
            }

$("#selDoesExistInSFDC").val(oListItem.get_item('DoesLeadAccountExistInSFDC')) 
;
            
$("#txtPasteURL").val(oListItem.get_item('PasteAccountURLFromSFDC'));
$("#txtParentNationalAccount").val(oListItem.get_item('ParentNationalAccount'));
            $("#txtSoldToName").val(oListItem.get_item('SoldToName'));
            
$("#txtSoldToLegalName").val(oListItem.get_item('SoldToLegalName'));
            $("#txtShortName").val(oListItem.get_item('ShortName'));
             
$("#selCustomerChannel").val(oListItem.get_item('CustomerChannel'));

//New field
            var CustomerSegmentationField = oListItem.get_item('CustomerSegmentationField');
            if (checkNotEmpty(CustomerSegmentationField)) {
   
$("#selCustomerSegmentationField").val(CustomerSegmentationField.get_lookupId()); 

function onQueryFailed(sender, args) {

        alert('Request failed. ' + args.get_message() + '\n' + 
args.get_stackTrace());
    }
</script>

這包括那部分嗎?

該錯誤提到您尚未加載該字段。

確保您加載了項目並且字段 static 名稱與“CustomerSegmentationField”匹配

clientContext.load(listItem);    
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM