Javascript x Category Fields x Total Values

Answered

Comments

4 comments

  • Stefan Ukena

    Hi Eduardo,

    most likely it is not working because you did not use an exact copy of the category names in your case-statements. In the code you posted, for example, you are using different characters for the dash ("-"). Case in point: when cheking for "0 - Não apresentou capacidade de bus..." you are using the regular dash, while in later switches you are using a different dash: "0 – Apresentou dificuldade para se comunica...................". Note the difference: "-" and "–". (If it looks the same on your screen, then maybe your font does not show the difference. In any case, these are different characters and thus the switch might fail.

    I would suggest only checking for the first character, which in your case is always a number, 0 through 3, by using the subString() method:

    switch(@Auto-desenvolvimento.subString(0,1))
    {
    case "0" : ...;
    case "1" : ...;
    ...
    }

    Hope this helps.

    Best,
    Stefan

    http://www.diekollaborateure.com/go/podio/help

    0
    Comment actions Permalink
  • Eduardo Rocha Tavares

    Hey, Stefan,

    I tried your solution (which is what I was looking for!) but now I get the following error:

    • Preview: Script error: TypeError: undefined is not a function

    I am far from being a javascript expert but I try! Do I have to start the code with something else? I am asking this because the following code is the ENTIRE code I pasted on the calculation field. This is the new one based on your suggestion:


    switch (@(C01) Auto-desenvolvimento.subString(0,1))
    {
    case "0": c01 = "0";
    break;
    case "1" : c01 = "1";
    break;
    case "2" : c01 = "2";
    break;
    case "3" : c01 = "3";
    break;
    }

    switch (@(C02) Comunicação.subString(0,1))
    {
    case "0": c02 = "0";
    break;
    case "1" : c02 = "1";
    break;
    case "2" : c02 = "2";
    break;
    case "3" : c02 = "3";
    break;
    }

    switch (@(C03) Criatividade.subString(0,1))
    {
    case "0": c03 = "0";
    break;
    case "1" : c03 = "1";
    break;
    case "2" : c03 = "2";
    break;
    case "3" : c03 = "3";
    break;
    }

    switch (@(C04)Decisão.subString(0,1))
    {
    case "0": c04 = "0";
    break;
    case "1" : c04 = "1";
    break;
    case "2" : c04 = "2";
    break;
    case "3" : c04 = "3";
    break;
    }

    switch (@(C05) Expertise / Conhecimento.subString(0,1))
    {
    case "0": c05 = "0";
    break;
    case "1" : c05 = "1";
    break;
    case "2" : c05 = "2";
    break;
    case "3" : c05 = "3";
    break;
    }

    resultado = parseInt(c01) + parseInt(c02) + parseInt(c03) + parseInt(c04) + parseInt(c05);

    0
    Comment actions Permalink
  • Stefan Ukena

    Hi Eduardo,

    I had a typo in my code: it must be substring() not subString(). Lower case s.

    You said that the switch is failing, you didn't mention that there is a syntax error reported by Podio. If it says "Preview = Script reference error: c05 is not defined" then this points to a different problem than what I assumed from your original post.

    Looking at your entire code (BTW: it's always best to post this right away when asking a question), I would suggest to simplify it like this (see below).

    Best,
    Stefan

    // Put the field values in some helper variables to make the code cleaner
    var field1 = @(C01) Auto-desenvolvimento;
    var field2 = @(C02) Comunicação;
    var field3 = @...;
    var field4 = @...;
    var field5 = @...;

    // Directly use the first character (which MUST be a digit)
    var c01 = parseInt (field1.substring(0,1));
    var c02 = parseInt (field2.substring(0,1));
    var c03 = parseInt (field3.substring(0,1));
    var c04 = parseInt (field3.substring(0,1));
    var c05 = parseInt (field3.substring(0,1));

    // This is your result. You don't need to assign it to anything, Podio will just use this value directly:
    c01 + c02 + c03 + c04 + c05;

    1
    Comment actions Permalink
  • Eduardo Rocha Tavares

    Stefan,

    Thank you! Worked like a charm!

    Regards,

    Eduardo

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk