Release Automation

  • 1.  Split array into multiple arrays

    Posted Oct 14, 2016 03:57 AM

    The use case is, i have an array of 'n' elements and i want split it into 5 different arrays and process them in parallel. As of now, there is not action which supports this requirement. Anyone has even came across such a scenario and way you handled it?

     

    Best regards,

    Amit Joshi



  • 2.  Re: Split array into multiple arrays
    Best Answer

    Posted Oct 14, 2016 09:07 AM

    You can use javascript action 

    Since the action have only 3 arrays parameters as output you should use 2 actions.

    First action script

    var length = arrInput1.length;
    var temp= length/5 ;
    var tmparry = arrInput1;
    var size = Math.ceil(temp);
    var arrOutput1 = tmparry.splice(0,size);
    var arrOutput2 = tmparry.splice(0,size);
    var arrOutput3 = tmparry.splice(0,size);

     

    The second javascript action

     

    var length = arrInput1.length;
    var temp= length/5 ;
    var tmparry = arrInput1;
    var size = Math.ceil(temp);
    var temp2= length-4*size;
    var x = tmparry.splice(0,size);
    var y = tmparry.splice(0,size);
    var z = tmparry.splice(0,size);
    var arrOutput1 = tmparry.splice(0,size);
    var arrOutput2 = tmparry.splice(0,temp2);

     

    The array output fields will use 5 different array parameters

    Hope this help , you probably can find other options to do that.



  • 3.  Re: Split array into multiple arrays

    Broadcom Employee
    Posted Oct 14, 2016 10:09 AM

    Here are some technical documents for becoming more familiar with the javascript action. It does not cover the use case you have asked about - Jacky's response handles that use case. This is just supporting material for becoming more comfortable with the javascript action itself since I knew it took me a few tries before I was comfortable.

     

    Split Strings Into Array With Execute JavaScript regex 

    Removing empty elements from Array Using Execute JavaScript action 

     

    Regards,

    Gregg

    http://www.ca.com/us/services-support/ca-support/ca-support-online/knowledge-base-articles.tec1906837.html