none
Taking multi line row count and inserting the count number in Task List column. RRS feed

  • Question

  • Dear All,

    I've Infopath multiline text box column in Document Library so I want to take the row count from multiline text box and this row count number need to add in Task List. So from Task list based on the number I need to create the workflow alert mail.

    (function () { 

        // Create object that have the context information about the field that we want to change it's output render  
        var bodyFiledContext = {}; 
        bodyFiledContext.Templates = {}; 
        bodyFiledContext.Templates.Fields = { 
            // Apply the new rendering for Body field on list view 
            "SCCount": { "View": bodyFiledTemplate } 
        }; 

        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext); 
    })(); 

    function bodyFiledTemplate(ctx) { 
    if(ctx.CurrentItem.Server_x0020_Name1 != ""){
    var lines = ctx.CurrentItem.Server_x0020_Name1.split("<br>");  
        return  lines.length;  }
    }

    First Part above code, Talking the row count from multiline text box and showing in column "SCCount"is working fine but when I try to insert it this count it is not working for me. Below is JavaScript code-- Please advice.

    var bodyFiledContext = {}; 
    (function () { 
        
        bodyFiledContext.Templates = {}; 
        bodyFiledContext.Templates.Fields = {  
            "SCCount": { "View": bodyFiledTemplate } 
        }; 

        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext); 
    })(); 
    var nom;
    var ItemId;
    function bodyFiledTemplate(ctx) { 
    if(ctx.CurrentItem.Server_x0020_Name1 != ""){
    var lines = ctx.CurrentItem.Server_x0020_Name1.split("<br>");  
        nom=lines.length;
    ItemId = ctx.CurrentItem.ID;

    ExecuteOrDelayUntilScriptLoaded(copy, "sp.js");
    }
    }
    var clientContext;
     var oListItem;
    var File;
    function copy() {
    debugger;
        clientContext = new SP.ClientContext("http://SP/IT");
        var oList = clientContext.get_web().get_lists().getByTitle('Shared Documents');//change the List name to the list that you want to copy item to
        oListItem = oList.getItemById(ItemId);
    File = oListItem.get_file();

                     clientContext.load(File); 
         clientContext.executeQueryAsync(onQuerymSucceeded,onQueryFailed);
       
    }

    function onQuerySucceeded() {
        alert('Item created');
    }
    function onQuerymSucceeded() {//if(File.get_checkOutType() == SP.CheckOutType.online) 
                    // File.checkOut();
        oListItem.set_item('SCCount', nom);
        oListItem.update();
        clientContext.load(oListItem);       
        clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed); 
       }
    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
    Tuesday, July 9, 2019 5:40 AM

Answers

  • Hi,

    Modify the code as below.

    <script type="text/javascript">
    (function (){
        // Create object that have the context information about the field that we want to change it's output render  
        var bodyFiledContext = {}; 
        bodyFiledContext.Templates = {}; 
        bodyFiledContext.Templates.Fields = { 
            // Apply the new rendering for Body field on list view 
            "SCCount": { "View": bodyFiledTemplate } 
        }; 
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext); 
    })(); 
    var nom;
    var ItemId;
    function bodyFiledTemplate(ctx) { 
    	if(ctx.CurrentItem.Server_x0020_Name1 != ""){
    		var lines = ctx.CurrentItem.Server_x0020_Name1.split("<br>");
    		nom=lines.length;
    		ItemId = ctx.CurrentItem.ID;
    		ExecuteOrDelayUntilScriptLoaded(copy, "sp.js");
    		return  lines.length;  
    	}
    }
    var clientContext;
     var oListItem;
    var File;
    function copy() {
    	debugger;
    	clientContext = new SP.ClientContext.get_current();
    	var oList = clientContext.get_web().get_lists().getByTitle('Shared Documents');//change the List name to the list that you want to copy item to
    	oListItem = oList.getItemById(ItemId);
    	File = oListItem.get_file();
    	clientContext.load(File); 
        clientContext.executeQueryAsync(onQuerymSucceeded,onQueryFailed);   
    }
    
    function onQuerySucceeded() {
        alert('Item created');
    }
    function onQuerymSucceeded() {
    	//if(File.get_checkOutType() == SP.CheckOutType.online) 
    	// File.checkOut();
        oListItem.set_item('SCCount', nom);
        oListItem.update();
        clientContext.load(oListItem);       
        clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed); 
    }
    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
    </script>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by SP2013Devp Tuesday, July 9, 2019 8:50 AM
    • Unmarked as answer by SP2013Devp Tuesday, July 9, 2019 10:57 AM
    • Marked as answer by SP2013Devp Wednesday, July 10, 2019 5:48 AM
    Tuesday, July 9, 2019 8:16 AM
    Moderator

All replies

  • Hi,

    Modify the code as below.

    <script type="text/javascript">
    (function (){
        // Create object that have the context information about the field that we want to change it's output render  
        var bodyFiledContext = {}; 
        bodyFiledContext.Templates = {}; 
        bodyFiledContext.Templates.Fields = { 
            // Apply the new rendering for Body field on list view 
            "SCCount": { "View": bodyFiledTemplate } 
        }; 
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext); 
    })(); 
    var nom;
    var ItemId;
    function bodyFiledTemplate(ctx) { 
    	if(ctx.CurrentItem.Server_x0020_Name1 != ""){
    		var lines = ctx.CurrentItem.Server_x0020_Name1.split("<br>");
    		nom=lines.length;
    		ItemId = ctx.CurrentItem.ID;
    		ExecuteOrDelayUntilScriptLoaded(copy, "sp.js");
    		return  lines.length;  
    	}
    }
    var clientContext;
     var oListItem;
    var File;
    function copy() {
    	debugger;
    	clientContext = new SP.ClientContext.get_current();
    	var oList = clientContext.get_web().get_lists().getByTitle('Shared Documents');//change the List name to the list that you want to copy item to
    	oListItem = oList.getItemById(ItemId);
    	File = oListItem.get_file();
    	clientContext.load(File); 
        clientContext.executeQueryAsync(onQuerymSucceeded,onQueryFailed);   
    }
    
    function onQuerySucceeded() {
        alert('Item created');
    }
    function onQuerymSucceeded() {
    	//if(File.get_checkOutType() == SP.CheckOutType.online) 
    	// File.checkOut();
        oListItem.set_item('SCCount', nom);
        oListItem.update();
        clientContext.load(oListItem);       
        clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed); 
    }
    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
    </script>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by SP2013Devp Tuesday, July 9, 2019 8:50 AM
    • Unmarked as answer by SP2013Devp Tuesday, July 9, 2019 10:57 AM
    • Marked as answer by SP2013Devp Wednesday, July 10, 2019 5:48 AM
    Tuesday, July 9, 2019 8:16 AM
    Moderator
  • You are great sir.. Thanks for your help.. its work perfectly..:)
    Tuesday, July 9, 2019 8:50 AM
  • Hi Dennis,

    For old entry script is showing correct count but if i'm doing new entry then the count is not showing, could you please advice.

    Thanks.

    Tuesday, July 9, 2019 10:57 AM
  • Hi,

    For new entry, we need add some jQuery code to set the SCCount field before save the item. We can use PreSaveAction function and add some code to achieve it.

    https://social.technet.microsoft.com/wiki/contents/articles/31330.sharepoint-using-presaveaction-function-on-custom-list-forms.aspx

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, July 10, 2019 2:04 AM
    Moderator
  • Hi Dennis,

    I just removed script tab from top-button and for new item issue resolved, below is the final code just pasting here so if it can help anyone here. Thanks


    (function (){
        // Create object that have the context information about the field that we want to change it's output render  
        var bodyFiledContext = {}; 
        bodyFiledContext.Templates = {}; 
        bodyFiledContext.Templates.Fields = { 
            // Apply the new rendering for Body field on list view 
            "SCCount": { "View": bodyFiledTemplate } 
        }; 
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext); 
    })(); 
    var nom;
    var ItemId;
    function bodyFiledTemplate(ctx) { 
    if(ctx.CurrentItem.Server_x0020_Name1 != ""){
    var lines = ctx.CurrentItem.Server_x0020_Name1.split("<br>");
    nom=lines.length;
    ItemId = ctx.CurrentItem.ID;
    ExecuteOrDelayUntilScriptLoaded(copy, "sp.js");
    return  lines.length;  
    }
    }
    var clientContext;
     var oListItem;
    var File;
    function copy() {
    debugger;
    clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('Shared Documents');//change the List name to the list that you want to copy item to
    oListItem = oList.getItemById(ItemId);
    File = oListItem.get_file();
    clientContext.load(File); 
        clientContext.executeQueryAsync(onQuerymSucceeded,onQueryFailed);   
    }

    function onQuerySucceeded() {
       // alert('Item created');
    }
    function onQuerymSucceeded() {
    //if(File.get_checkOutType() == SP.CheckOutType.online) 
    // File.checkOut();
        oListItem.set_item('SCCount', nom);
        oListItem.update();
        clientContext.load(oListItem);       
        clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed); 
    }
    function onQueryFailed(sender, args) {
        //alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

    Wednesday, July 10, 2019 5:48 AM
  • Hi,

    Glad to hear that you solve this issue, thanks for your sharing.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, July 10, 2019 6:48 AM
    Moderator