1

Iam getting this error "Request failed. Value does not fall within the expected range" when i create list with choice Field/column and Taxonomy Field.

Here is my code for creating the List, and then in my second function i create all the Fields:

 var clientContext = new SP.ClientContext(_spHostUrl);
                        var oWebsite = clientContext.get_web();

                        var listCreationInfo = new SP.ListCreationInformation();
                        listCreationInfo.set_title('GNTiles_');
                        listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
                        this.oList = oWebsite.get_lists().add(listCreationInfo);

                        clientContext.load(oList);

                        clientContext.executeQueryAsync(function () {
                            addGNTilesFieldsToList(gnPagesId, termStoreId, termSetIdProcess);
                            console.log('List GNTiles created..');
                        }, function (sender, args) {
                            console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
                        });

Creating all Fields:

        var addGNTilesFieldsToList = function (gnPagesId, termStoreId, termSetIdProcess) {
        var clientContext = new SP.ClientContext(_spHostUrl);

        var oList = clientContext.get_web().get_lists().getByTitle('GNTiles_');

        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'Text\' Type=\'Note\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'Class\' Type=\'Text\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'TextClass\' Type=\'Text\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'ClickAction\' Type=\'Text\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'TextAnchor\' Type=\'Text\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'ElementType\' Type=\'Text\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'TextRotate\' Type=\'Text\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'sPropJSON\' Type=\'Note\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'GoToPage\' Type=\'Text\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'Corner\' Type=\'Text\' />', true, SP.AddFieldOptions.defaultValue);
        this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName="GNPage" Type="Lookup" List="' + gnPagesId + '" ShowField="GNPage" RelationshipDeleteBehavior="None" />', true, SP.AddFieldOptions.defaultValue);

        var choiceDropDownField = clientContext.castTo(
        this.oField = oList.get_fields().addFieldAsXml('<Field Type="Choice" DisplayName="svgShape" Name="svgShape" Format="Dropdown" />', true, SP.AddFieldOptions.addToDefaultContentType), SP.FieldChoice);
        var availableDropChoices = Array("circle", "ellipsis", "rect", "path", "polygon", "polyline");
        choiceDropDownField.set_choices(availableDropChoices);
        choiceDropDownField.update();

        var taxFieldProcess =
             '<Field Type="TaxonomyFieldType" DisplayName="Process"  ShowField="Term1033" Required="FALSE" EnforceUniqueValues="FALSE"  StaticName="Process" Name="Process" > \
                 <Default /> \
                 <Customization> \
                    <ArrayOfProperty> \
                        <Property>\
                            <Name>SspId</Name>\
                            <Value xmlns:q2="http://www.w3.org/2001/XMLSchema" p4:type="q2:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">' + termStoreId + '</Value>\
                        </Property> \
                        <Property>\
                            <Name>TermSetId</Name>\
                            <Value xmlns:q2="http://www.w3.org/2001/XMLSchema" p4:type="q2:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">' + termSetIdProcess + '</Value>\
                        </Property> \
                        <Property>\
                            <Name>TextField</Name>\
                            <Value xmlns:q2="http://www.w3.org/2001/XMLSchema" p4:type="q2:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance"></Value>\
                        </Property> \
                    </ArrayOfProperty> \
                   </Customization> \
              </Field>';

        this.oField = oList.get_fields().addFieldAsXml(taxFieldProcess.toString(), true, SP.AddFieldOptions.defaultValue);

        var fieldNumber = clientContext.castTo(oField, SP.FieldNumber);
        fieldNumber.update();
        clientContext.load(oField);
        clientContext.executeQueryAsync(function () {
            console.log('Fields created..');
        }, function (sender, args) {
            console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        });
    }

I get this error first time i try to create the List and Fields, List always get created, but NOT the Fields. So each time i have to delte the List, and re-create it, then i dont get this error message. By googling a litle i found that it maybe can be List View Treshold value issue, and i did change the Treshold value without any luck....

How can i fix this?

reg gonadn

  • To troubleshoot your error, simplify your code so that it only adds 1 field per run. Afterwards you should be able to identify the faulty lines. – Mx. Oct 18 '16 at 11:33
0

Could ba any numer of problems...

What are you trying to do with the code-lines:

this.oField = oList.get_fields().addFieldAsXml(taxFieldProcess.toString(), true, SP.AddFieldOptions.defaultValue);
var fieldNumber = clientContext.castTo(oField, SP.FieldNumber);
fieldNumber.update();
  • you create (in oField) a TaxonomyField
  • you cast (in fieldNumber) the TaxonomyField to NumberField (I think this breaks your code)
  • you update fieldNumber

First I would remove all the this.oField =-stuff, as you're not using it anyhow. Second I would try adding one field to the list and see if that works. Work your way up to all the fields from there.

You could also check on the last usage of oField: You always assing this.oField, but in the var fieldNumber-Line you access oField without this. The two need not be the same...

  • I found the problom and its when i try to set lookup column to another list i have. – user3629354 Oct 20 '16 at 8:33
  • What is the value of gnPagesId? I think it should be something like {5D184D01-082C-4831-8757-CA2C98F05221} - including the baces and dashes.. – Nils Oct 20 '16 at 21:38
0

I found the problom and the error is because of lookup Field to another list i have. These lines are giving the error:

var lookupSchema = "<Field Type='Lookup' DisplayName='GNPage' Name='GNPage' StaticName='GNPage' List='" + gnPagesId + "' ShowField='Title' RelationshipDeleteBehavior='None' />";
        oList.get_fields().addFieldAsXml(lookupSchema, true, SP.AddFieldOptions.defaultValue);

All other Fields get created if i comment out these lines above.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.