A query in Inbound email actions

devservicenow k
Tera Contributor

I am Creating Inbound email action and creating case Record.

After creating if the inbound email Domain is (eg,gmail.com).

the particular Account record with the (gmail.com ) to be selected and stored in Account field in that case Record, i have created the Script but it is not getting updated in the Case record, but in the Logs it is currectly giving the output.

suggest me what changes do i need to do 

 

 

1 ACCEPTED SOLUTION

Please check the below code:-

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
current.u_insp_email = email.from;
var domain = email.from.split('@')[1];
gs.info("Name is: " + domain);

var gr = new GlideRecord('customer_account');
gr.addEncodedQuery('u_emailidCONTAINS' + domain);

gr.query();

if (gr.next()) {
current.account = gr.sys_id;;
current.update();
gs.info("Name is2222: " + gr.name);
gs.info("Name is111: " + current.account);

if(gr.contact==''){
var update = new GlideRecord('sys_user')
update.addQuery('email',email.from)
update.query();
if(update.next())
{
gr.contact=update.sys_id;
gr.update();
}
else
{
var create = new GlideRecord('sys_user')
create.initialize();
create.email=email.from;
create.name=email.from;
create.user_name=email.from;
create.insert();
gr.contact=create.sys_id;
gr.update();
}
}
}

//current.u_insp_email = domain;
})(current, event, email, logger, classifier);

 

Please mark my answer as correct based on Impact. 

View solution in original post

14 REPLIES 14

Can you share the screenshot of the record? is the i icon visible beside the contact field?

 

 yeah its available 

Hello,

 

What do you mean when you say the user is not getting saved here? what does the i icon show when you click on it?

but it is not getting saved automatically

 

Please check the below code:-

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
current.u_insp_email = email.from;
var domain = email.from.split('@')[1];
gs.info("Name is: " + domain);

var gr = new GlideRecord('customer_account');
gr.addEncodedQuery('u_emailidCONTAINS' + domain);

gr.query();

if (gr.next()) {
current.account = gr.sys_id;;
current.update();
gs.info("Name is2222: " + gr.name);
gs.info("Name is111: " + current.account);

if(gr.contact==''){
var update = new GlideRecord('sys_user')
update.addQuery('email',email.from)
update.query();
if(update.next())
{
gr.contact=update.sys_id;
gr.update();
}
else
{
var create = new GlideRecord('sys_user')
create.initialize();
create.email=email.from;
create.name=email.from;
create.user_name=email.from;
create.insert();
gr.contact=create.sys_id;
gr.update();
}
}
}

//current.u_insp_email = domain;
})(current, event, email, logger, classifier);

 

Please mark my answer as correct based on Impact.