The CreatorCon Call for Content is officially open! Get started here.

Inbound Email Action

Dizy M
Tera Expert

Hi everyone. Can you please help me on this one?

 

I created an email notification wherein the Employee's People Lead can choose between "Yes" or "No".

DizyM_0-1690260344404.png

 

What happened was when I click the "Click here for Yes" it was working fine and I received the email in the instance ,but it doesn't update our field " Has any progress", im not sure why that happened.

Field: has_any_progress

 

And if someone's email address(He's not the Employee's People Lead)  click any of the choices , either "Click here for Yes" or "Click here for No" , it seems like this line is not working.

else {
current.comments = "\n\n\n******The ID - " + frm + " is not the employee's people lead. Hence, their response could not be updated in this record.******";

 

Inbound Email Action:

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
	

	if (current.getTableName() == "employee_table") {
		

		var sub = email.subject.trim().toLowerCase();
		var bodyText = email.body_text;
		var frm = email.origemail;
		var usrSysID;
		//var listArr = [];

		var list = current.employee_people_lead;

		//listArr = list.split(',');

		var usr = new GlideRecord("employee_table");
		usr.addQuery("employee_people_lead.email", frm);
		usr.addQuery("employee_people_lead.active", true);
		usr.query();

		if (usr.next()) {
			usrSysID = usr.sys_id;
		
		} 
		else {
			current.comments = "\n\n\n******The ID - " + frm + " is not the employee's people lead. Hence, their response could not be updated in this record.******";
		}

			if (usrSysID == list) {
				
				if (sub.indexOf("no") >- 1){
					current.has_any_progress = "no";
					
				} else if(sub.indexOf("yes") >- 1){
					current.has_any_progress = "yes";
				}
			}
		
		
		current.comments = "Reply from: " + email.origemail + "\n\n" + bodyText;	
		current.update();
	}

})(current, event, email, logger, classifier);

 

 

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage
Mega Sage

Hello @Dizy M 

 

Try below script. As you already have employee_lead reference (Hoping it to be reference to user table) in current record, you can directly compare instead of the GlideRecord

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
	

	if (current.getTableName() == "employee_table") {
		
               gs.info("Inside the inbound action!");
		var sub = email.subject.trim().toLowerCase();
		var bodyText = email.body_text;
		var frm = email.origemail;
		var usrSysID;
				gs.info("From email: " + frm)

			if (current.employee_people_lead.email == frm) {
				gs.info("inside true block!");
				if (sub.indexOf("no") > -1){
					current.has_any_progress = "no";
					
				} else if(sub.indexOf("yes") > -1){
					current.has_any_progress = "yes";
				}
			}
                     else {
gs.info("Inside else block!");
			current.comments = "\n\n\n******The ID - " + frm + " is not the employee's people lead. Hence, their response could not be updated in this record.******";
		}
		
		
		current.comments = "Reply from: " + email.origemail + "\n\n" + bodyText;	
		current.update();
	}

})(current, event, email, logger, classifier);

 

Verify syntax, field names and  logs to debug.

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

2 REPLIES 2

Ahmmed Ali
Mega Sage
Mega Sage

Hello @Dizy M 

 

Try below script. As you already have employee_lead reference (Hoping it to be reference to user table) in current record, you can directly compare instead of the GlideRecord

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
	

	if (current.getTableName() == "employee_table") {
		
               gs.info("Inside the inbound action!");
		var sub = email.subject.trim().toLowerCase();
		var bodyText = email.body_text;
		var frm = email.origemail;
		var usrSysID;
				gs.info("From email: " + frm)

			if (current.employee_people_lead.email == frm) {
				gs.info("inside true block!");
				if (sub.indexOf("no") > -1){
					current.has_any_progress = "no";
					
				} else if(sub.indexOf("yes") > -1){
					current.has_any_progress = "yes";
				}
			}
                     else {
gs.info("Inside else block!");
			current.comments = "\n\n\n******The ID - " + frm + " is not the employee's people lead. Hence, their response could not be updated in this record.******";
		}
		
		
		current.comments = "Reply from: " + email.origemail + "\n\n" + bodyText;	
		current.update();
	}

})(current, event, email, logger, classifier);

 

Verify syntax, field names and  logs to debug.

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

@Ahmmed Ali  Thank you so much for your help !