Calculations by Referenced app status

Comments

1 comment

  • Rainer Grabowski

    Hi Joe,

    yes there is a way: 

    var cat = @all of your category field;
    count = 0;
    for(var i = 0; i < cat.length; i++){
    if(cat[i] == "XYZ"){
    count++;
    };
    count

    "XYZ" is a placeholder for the category name. If it is multi choice category field:

    if(cat[i].indexOf("XYZ") > -1){

    If you want a list of of all categories which have been selected:

    var cat = @all of your category field;
    var uniqueCat = cat.filter(function(item, pos) {
    return cat.indexOf(item) == pos;
    });
    var list = [];
    for(var i = 0; i < uniqueCat.length; i++){
    count = 0;
    for(var j = 0; j < cat.length; j++){
    if(uniqueCat[i] == cat[j]){
    count++;
    }}
    list.push(uniqueCat[i] + ": " + count);
    };
    list.join("\n")

    Result:
    XYZ: 2
    ABC:1
    GHI: 3

    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk