0
votes

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"

Need to add a new field so I mirrored the "CustomerType" by creating: SharePoint List, "CustomerSegmentation" with values SharePoint List, "Customer" with lookup column named, "CustomerSegmentation" pulling values from "CustomerSegmentation"

I copied the HTML, JavaScript, etc. - It is all working well for selecting a value and creating the item in the "customer" list. However, when I try to display the selected value on a 'display' HTML form using:

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

I get this error: Uncaught Error: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. 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) at onQuerySucceeded (Display-New-Request.aspx?itemID=9076:1678) at Array. (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) at Array. (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)

I would greatly appreciate help - thank you!!

<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>

Does this cover that part?

1

1 Answers

0
votes

The error mentions you have not loaded the field.

Make sure you loaded the item and the field static name matches ‘CustomerSegmentationField’

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