none
What JavaScript looping code can call a function 30 times, passing SharePoint List Column Names in this way? RRS feed

  • Question

  • Hi there

    I am calling a function "setupSection()" by passing SP LIst Column Names as follows:
    List Column names start with a number "1", "2" etc. in sequence.

    setupSection("Section1", "1-Initiator", "1-User-Type", "1-Supervisor");
    setupSection("Section2", "2-User-Accounts", "2-User-Manager", "2-User-Title");
    setupSection("Section3", "3-Hardware and phone", "3-Hardware", "3-Business-Justification");
    setupSection("Section4", "4-Software", "4-Price", "4-Business-Justification");
    //A total of 30 similar calls to setupSection()

    What code can loop through 30 times and call "setupSection()" passing it right arguments (e.g. column names starting with "1" first time, then column names starting with "2" second time and so on...)?

    Thanks so much.


    • Edited by ran009 Monday, March 6, 2017 8:31 PM
    Monday, March 6, 2017 8:20 PM

Answers

  • Hi,

    We can use the following code snippet to achieve it.

    <script type="text/javascript">
    function setup(){
    	for(var i=1;i<=30;i++){ 
    		setupSection("Section"+i, i+"-Initiator", i+"-User-Type", i+"-Supervisor");
    	}
    }
    </script>

    Best Regards,

    Dennis


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

    • Marked as answer by ran009 Wednesday, March 8, 2017 2:01 AM
    Tuesday, March 7, 2017 5:08 AM
    Moderator

All replies

  • You should use the array they're from.
    Monday, March 6, 2017 8:27 PM
  • I would rather prefer to loop through list column names and then based on starting character send column names to the function. No hardcoded column names.

    Will appreciate the code.

    Thanks so much.

    Monday, March 6, 2017 8:29 PM
  • Hi,

    We can use the following code snippet to achieve it.

    <script type="text/javascript">
    function setup(){
    	for(var i=1;i<=30;i++){ 
    		setupSection("Section"+i, i+"-Initiator", i+"-User-Type", i+"-Supervisor");
    	}
    }
    </script>

    Best Regards,

    Dennis


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

    • Marked as answer by ran009 Wednesday, March 8, 2017 2:01 AM
    Tuesday, March 7, 2017 5:08 AM
    Moderator