Customer Portal

CTL - Add to lookup table?

Comments 4

  • Avatar
    avackova
    0
    Comment actions Permalink
    Hello Bernie,
    putting data into lookup table from CTL is not possible. More over, lookup is performed not directly on lookup table, but on the lookup object created from lookup table. So even from java it wouldn't work as you expect.
    What about sorting the users before preforming lookup? Then you know that users with the same possible e-mails are grouped together.
  • Avatar
    berniedurfee
    0
    Comment actions Permalink
    I'm not sure how sorting would help. Here's the situation...

    Database

    Firstname Lastname Email
    John Smith js1@mycompany dot com
    Jane Smith js2@mycompany dot com


    New User List

    Firstname Lastname
    Jerry Smith
    Jacob Smith


    So I start by creating a lookup table containing all of the existing email addresses in the database.

    I process the first incoming record and choose the email address: js1@mycompany dot com
    Check the lookup table, js1@mycompany dot com already exists, so I increment the sequence number: js2@mycompany dot com
    Check the lookup table again, js2@mycompany dot com already exists, so I increment the sequence number: js3@mycompany dot com
    Check the lookup table again, js3@mycompany dot com doesn't exist, so that's the email address I'll insert...


    Now I process the second incoming record and choose the email address: js1@mycompany dot com
    Check the lookup table, js1@mycompany dot com already exists, so I increment the sequence number: js2@mycompany dot com
    Check the lookup table again, js2@mycompany dot com already exists, so I increment the sequence number: js3@mycompany dot com

    Now how do I know that js3@mycompany dot com doesn't exist? It's not in the database lookup table because it's not in the database yet.

    What I wanted to do is to have an empty lookup table that I can add email addresses that I choose, so I can check that table in addition to the database lookup table to make sure that the email address I choose is unique.

    Right now I have this implemented in Java, by just using a class variable Set as a place where I can store the chosen email addresses as I go through the incoming records. I was hoping to stick to CTL though and not have to maintain Java code.


    Thanks,
    Bernie
  • Avatar
    avackova
    0
    Comment actions Permalink
    Hello Bernie,
    oh, I see. You can use list type and .in. operator:
    //#TL
    string key = "";
    int counter;
    string email;
    list newEmails;

    // Transforms input record into output record.
    function transform() {
    counter = 2;
    key = concat($first_name, '.', $last_name);
    email = concat(key, "@mycompany.com");
    while (!isnull(lookup(LookupTable0,email).email)) {
    email = concat(key, counter++, "@mycompany.com");
    }
    while (email.in.newEmails) {
    email = concat(key, counter++, "@mycompany.com");
    }
    push(newEmails,email);
    $0.* := $0.*;
    $email := email;
    return ALL
    }


    This is my previous (with sorted records) solution:
    //#TL
    string key = "";
    string tmpKey;
    int counter;
    string email;

    // Transforms input record into output record.
    function transform() {
    tmpKey = concat($first_name, '.', $last_name);
    if (tmpKey != key) {//first name and last name different than in previous record
    key = tmpKey;
    counter = 2;
    email = concat(key, "@mycompany.com");
    while (!isnull(lookup(LookupTable0,email).email)) {
    email = concat(key, counter++, "@mycompany.com");
    }
    }else{
    email = concat(key, counter++, "@mycompany.com");
    }
    $0.* := $0.*;
    $email := email;
    return ALL
    }
  • Avatar
    berniedurfee
    0
    Comment actions Permalink
    Excellent!

    I didn't realize that you can create 'class scoped variables' in CTL.

    Thanks!

Please sign in to leave a comment.