Customer Portal

String index out of range: does not make sense

Comments 4

  • Avatar
    lvalicek
    0
    Comment actions Permalink
    When I tried your code I did not have any problems and I obtained required result. Maybe the problem is in your input data or in metadata. Can you please show us your input data and metadata and also full stackTrace?

    Enclosed are the files I used for your code: InputFile, OutputFile and GraphString.grf.

    Code I used is following:
    function integer transform() {
    $0.Field1 = $0.Field1.substring(0,3) + "-" + $0.Field1.substring(3,4);
    return ALL;
    }

    Regards
  • Avatar
    pro7
    0
    Comment actions Permalink
    Thanks for the reply. The input is from a database. I should mention that I am new to CloverETL. I am supporting a set of graphs that were developed by someone else so I'm trying to familiarize myself with the tool. This is not a critical issue but it just bugs me because it is such a simple thing and I don't know why I get the error. More info in attached.

    Thanks again
  • Avatar
    avackova
    0
    Comment actions Permalink
    Hello,
    all looks fine in your graph. I believe, that you get shorter string in the sprtele_phone_number, but not necessarily in the first record. Try the following transformation instead of original one:
    //#CTL2

    // Transforms input record into output record.
    function integer transform() {
    $0.Student_ID = $0.spriden_id;
    $0.Prefix_NM = $0.spbpers_name_prefix;
    $0.First_NM = $0.spriden_first_name;
    $0.Middle_NM = $0.spriden_mi;
    $0.Last_NM = $0.spriden_last_name;
    $0.Suffix_NM = $0.spbpers_name_suffix;
    $0.Addr_1 = $0.spraddr_street_line1;
    $0.Addr_2 = $0.spraddr_street_line2;
    $0.City = $0.spraddr_city;
    $0.State = $0.spraddr_stat_code;
    $0.Postal_CD = $0.spraddr_zip;
    $0.Addr_Type = $0.spraddr_atyp_code;
    $0.PIDM = $0.apbcons_pidm;
    $0.Class = $0.apbcons_pref_clas;
    printErr(“Whole phone number:“ + $0.sprtele_phone_number);
    printErr(“Part 1:“ + sprtele_phone_number.substring(0,3));
    printErr(“Part 2:” + $0.sprtele_phone_number.substring(3,4));
    $0.Phone_Num = $0.sprtele_phone_area+"-"+$0.sprtele_phone_number.substring(0,3) + "-" + $0.sprtele_phone_number.substring(3,4);

    return ALL;
    }

    Then we will know exactly with which value the problem occurs.
  • Avatar
    pro7
    0
    Comment actions Permalink
    Thank you. I did not know about the printErr() function. This helped me find the error. As you suspected in your first reply, there was a problem with the input data. Of six thousand rows there were three with bad data. I can add logic to check length before trying to substring.

    Thanks again for your help

Please sign in to leave a comment.