0

I have used custom list having number of columns to display count.I have applied REST approach to get count.Now I am trying to display that count in a column.I used fd.field().value('Default title') in a script editor.(both api code and fd.field().value('Default title') code are in a same script editor).While using 'fd',I am getting error as fd is undefined.So is there any approach to display rest api output into a column?

Code:

    getListItemsForView(_spPageContextInfo.webAbsoluteUrl,<List name>,<View 
    Name>)
.done(function(data)
{
     var items = data.d.results;
     fd.field(<column_name>).value(data.d.results.length);
     for(var i = 0; i < items.length;i++) {
         console.log(items[i].Title);
     }    
})
.fail(
function(error){
    console.log(JSON.stringify(error));
});

  • please post your code for reference, are you using js link to display count...? – Siddharth Vaghasia Jul 25 at 6:55
  • please refer the code – user85213 Jul 25 at 7:02
  • what is fd object defined or declared and what is its type ? – Siddharth Vaghasia Jul 25 at 7:06
  • fd is forms designer manager global variable. I got this solution(to use fd) from spform.com/javascript-framework/…. I added same code in sharepoint designer too but it is not working – user85213 Jul 25 at 7:08
  • are you trying to display count in list forms or list view ? – Siddharth Vaghasia Jul 25 at 7:09
0

If you are adding the list items count in another list then in .done function, you need to make another REST call to add/update the list item in another list.

If You want to create new record in another list then you can use something like this in .done function:

$.ajax({  
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Your List Name')/items",  
    type: "POST",  
    headers: {  
        "accept": "application/json;odata=verbose",  
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
        "content-Type": "application/json;odata=verbose"  
    },  
    data: "{__metadata:{'type':'SP.Data.YourlistnameListItem'}, ItemCount:" Your list item count "}",  
    /*Assuming you have added ItemCount column to add item count and you can add more columns by splitting with ,*/  
    success: function(data) {  
        console.log(data.d.results);  
    },  
    error: function(error) {  
        alert(JSON.stringify(error));  
    }  
}); 

Reference for Add/Update item in SharePoint list using REST:

CRUD Operations On A SharePoint List Using REST API.

0

To customize list view you have to use JS link.....

I would suggest you to go through this link to understand concept and then modify it for your purpose.

<script type="text/javascript">  
(function () {  
    // Create an object that have the context information about the fields that we want to change the rendering of.   
    var nameFiledContext = {};  
    nameFiledContext.Templates = {};  
    nameFiledContext.Templates.Fields = {  
        // Apply the new rendering for these fields on List View  
        "<ColumnName>": { "View": nameFiledTemplate }  
    };  
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(nameFiledContext);  
})();  

// This function provides the rendering logic for the list view  
function nameFiledTemplate(ctx) {  

getListItemsForView(_spPageContextInfo.webAbsoluteUrl,<List name>,<View 
    Name>)
.done(function(data)
{
     var items = data.d.results;
     return data.d.results.length;    
})
.fail(
function(error){
    console.log(JSON.stringify(error));
});

}  
</script>  
  • Thanks...I will try it – user85213 Jul 25 at 7:18
  • I tried this approach but it is not executing nameFiledTemplate function – user85213 Jul 25 at 8:08
  • Did you replace column name with actual internal name of column – Siddharth Vaghasia Jul 25 at 8:44
  • yes,I replaced it – user85213 Jul 25 at 9:01
  • I am applying getListItemsForView function to get view count from a different list say list 1 and after getting count I am trying to assign it in list 2's column i.e.nameFiledContext.Templates.Fields = { // Apply the new rendering for these fields on List View "<ColumnName>": { "View": nameFiledTemplate } }; here,in place of column name I am passing list2's column name. So is it causing an issue? – user85213 Jul 25 at 9:06

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.