Creating a caller from an inbound email action

Alexandra2
Tera Contributor

Hi I am using an inbound email action to parse an email into a 'Customer Interaction' on the 'sn_customerservice_customer_interaction' table. We created a "Callers" table which extends the customer contact table and within my inbound action I have code to create a new caller from the email address within 'email.from.'

It's setting the email on the email field in the interaction form and everything else works with the inbound action but the thing I've been trying to fix is it creating a new caller and inserting that information into the reference fields on the interaction form.

It does create a new user in the sys_user table but I need that record in the Callers table 

Any and all help is very much appreciated!

 

Code:

 

//Query callers table if caller exists 
var newCaller = new GlideRecord('u_callers');
    newCaller.addQuery('email', current.email);
    newCaller.query();


//If no caller exists with that email address, create a new caller
    if (!newCaller.next()) {
        current.u_first_time_calling = true;
        newCaller.newRecord();
        newCaller.user_name = current.email;
        newCaller.email = current.email;
	    newCaller.first_name = current.first_name;
	    newCaller.last_name = current.last_name;
        newCaller.phone = current.phone;
        newCaller.insert();
    }
    current.u_caller = newCaller.getUniqueValue();
4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

Bit confused. Is it or  is it not creating user or what is expected kindly you kindly help clearing.

It is not creating a user, to clarify:

I have a custom table called 'u_callers' which is supposed to be a table of callers (i.e. anyone who will email into the instance). I need to take that email address and create a caller in that table does that make more sense?

 

They won't actually be users of the system but this is just to keep track of if they have emailed in before or if they are first time callers (first time emailing in).

And when I say it is not creating a user I mean it is not creating a caller in the caller's table as it should.

Alexandra2
Tera Contributor

I also tried this way of creating and getting the user record, and from there inserting the record into the callers table and nothing.

 var user = new GlideRecord('sys_user');
        user.addQuery('email', email.from.toString());
        user.query();
        if (!user.next()) {
            user.initialize();
            user.email = email.from;
            user.insert();
            var newCaller = new GlideRecord('u_callers');
            newCaller.addQuery('email', email);
            if (!newCaller.next()) {
                newCaller.initialize();
                newCaller.email = user.email;
				newCaller.insert();

            }
	}