3

I am getting the following screen shot error. I have used all related JS Files

oListItem.get_fieldTypeKind();

enter image description here

My Code :

   var clientContext = new SP.ClientContext.get_current();
//geting SupplierMaster list by Title 
var oList = clientContext.get_web().get_lists().getByTitle('SupplierMaster');
var viewCollection = oList.get_views();
//geting SupplierMaster list Fieds by ViewName

 var view = viewCollection.getByTitle("All Items");
var collListItem = view.get_viewFields();

clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
function onQuerySucceeded(sender, args) {
    var listItemEnumerator = collListItem.getEnumerator();
    //Binding data to Suppliers dropdown list
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        var FieldType = oListItem.get_fieldTypeKind();            
        SupliersDropDownArray.push({
            text: oListItem

        })
    }
    $("#ddlSuppliers").data("kendoDropDownList").dataSource.read();

}
3

3 Answers 3

1

Field type can not be retrieved from list view. You can get it from list fields. So you can find your fields under a particular content type by following way.

var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle("Test 1");
var ct = list.get_contentTypes().getById("0x0104002AD7A8FC77B5644390D0D7372FEB55FB");
var fields = ct.get_fields();
context.load(fields)
context.executeQueryAsync(printFieldNames, onError);


function printFieldNames() {
    var e = fields.getEnumerator();
    while (e.moveNext()) {
        var f = e.get_current();
        console.log(f.get_typeAsString());
        console.log(f.get_title());
        console.log(f.get_fieldTypeKind());
    }
}

function onError(sender, args) {
    console.log(args.get_message());
}

PS: list.get_fields() will give you the all fields (hidden and others). So its better to find them under a particular content type.

1

You are missing context.load statement. In client object model, context.executeQueryAsync is used to make call to SharePoint to get what you specified in context.load method. Add load method before calling executeQueryAsync will solve your problem.

Also note that, if you are loading an object, all of its properties will not return from server (to keep packet size small for better performance). In such case you need to explicitly define what properties you want to load. So you require clientContext.load(objectToLoad, 'Include(Properties2, Properties2)');

0

from view.get_viewFields(), you get only field name. you have to do like below

var clientContext = new SP.ClientContext.get_current();
//geting SupplierMaster list by Title 
var oList = clientContext.get_web().get_lists().getByTitle('SupplierMaster');
var viewCollection = oList.get_views();
//geting SupplierMaster list Fieds by ViewName

var view = viewCollection.getByTitle("All Items");
var collListItem = view.get_viewFields();
var fields = oList.get_fields();
clientContext.load(fields);
clientContext.load(collListItem );

clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
function onQuerySucceeded(sender, args) {
var viewfieldnames = collectionToArray(collListItem);

var fieldEnumerator = fields.getEnumerator();

//Binding data to Suppliers dropdown list
while (fieldEnumerator.moveNext()) {
    var field = fieldEnumerator.get_current();
        if (!field.get_hidden()) {
            var fieldName = field.get_internalName();
            var found = $.inArray(fieldName, viewfieldnames) > -1;
            if (found) {
                 var oListItem = field.get_title();
    var FieldType = field.get_fieldTypeKind();            
    SupliersDropDownArray.push({
        text: oListItem

    })
            }

}
$("#ddlSuppliers").data("kendoDropDownList").dataSource.read();

}

function collectionToArray(collection) {
var items = [];
var e = collection.getEnumerator();
while (e.moveNext()) {
    var item = e.get_current();
    items.push(item);
}
return items;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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