Inbound mails are not added to activity

tomopl
Kilo Contributor

Hi there,

I have an inbound action against "sys_data_source" table. This action triggers the Scheduled Imports (hence it is against that certain table) when the mail has an attachment or creates a new task in our table (it extends the default "Task" table) when there is no file attached. The problem is, I don't know how to add the whole mail to the activity field (I've seen this working in other applications). It probably doesn't add the mail to that field because the first created record in the script is against the "sys_data_source" table, but I'm not sure about that. I have "Sent/Received Emails" filter selected when I right click the field, also there was an option in SN to show emails only to certain groups, that didn't work either. I know I can add an extra field to our table and just copy the mail body to it, but we want to use the default activity functionality.

Instance details:

Build name: HEAD (Fuji)

Build date: 10-29-2015_1529

Build tag: glide-fuji-12-23-2014__patch10-10-21-2015

1 ACCEPTED SOLUTION

Not actually ,I   misunderstood that you are having two issues... one for attachments and other is emails in activity log.



I remember when our client requested to show SLA emails on related Incident itself. The only way possible is to create a duplicate record of that email (sys_email record) and change the target table and target field values in new record.


View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi Tomasz,



can you please share your code ?



Regards, Bharat


I can share some part of it. Rest is unrelevant to the problem. In that script I have a function: (don't mind the logs)



function insertRequest(service) {



  var gr = new GlideRecord('my_target_table');



  if (service) {


  gs.log('[Mail Attachment Import] - Inserting request for ' + service + ' service line');


  gr.u_service = service.toUpperCase();


  } else {


  gs.log('[Mail Attachment Import] - Inserting "blank" ticket');


  gr.short_description = email.subject;


  gr.description = email.body_text;


  }



  if(email.body.priority != undefined) {


  gr.priority = email.body.priority;


  }



  if(email.body.rfi != undefined) {


  gr.u_rfi = email.body.rfi;


  }



  if(email.body.short_description != undefined) {


  gr.short_description = email.body.short_description;


  }



  if(email.body.description != undefined) {


  gr.u_description = email.body.description;


  }



  if(email.body.user_organization != undefined) {


  gr.u_user_s_organization = email.body.user_organization;


  }



  if(email.body.user_organization_others != undefined) {


  gr.u_user_organization_s_others = email.body.user_organization_others;


  }



  if(email.body.country_or_organization != undefined) {


  gr.u_country_or_organization = email.body.country_or_organization;


  }



  gr.u_region = 'c032afbf6fb0b1004e62bc775b3ee489';// region is NA



  if(email.body.category != undefined) {


  gr.u_category = email.body.category;


  }



  if(email.body.product_codes != undefined) {


  gr.u_item_list = email.body.product_codes.replace(/,/g, "\n")


  }



  gr.created_by = email.from;


  gr.contact_type = 'email';



  var insertedID = gr.insert();



  if (insertedID) {


  gs.log('[Mail Attachment Import] - Successfully created new ticket with sys ID: ' + insertedID + ', priority: ' + gr.priority + ', RFI: ' + gr.u_rfi + ', description: ' + gr.u_description + ', category: ' + gr.u_category + ', product codes: ' + gr.u_item_list + ', service: ' + gr.u_service + ', short description: ' + gr.short_description + ', user organization: ' + gr.u_user_s_organization + ', user organization others: ' + gr.u_user_organization_s_others + ', country or organization: ' + gr.u_country_or_organization + ', priority: ' + gr.priority);


  } else {


  gs.log('[Mail Attachment Import] - Failed to insert new ticket');


  }



}



That simple function inserts a new ticket to my table, which is an extended task table, when there is no attachment in the mail and with provided data in body. I tried insertWithReferences(). None of the Business rules on the "my_target_table" have something like setWorkflow(false) that could block any other Task rules. Am I missing something?


Hi Tomsaz,



You are not using current object of inbound action to insert a record but a custom GlideRecord Object to insert a record into a task based table. To copy email body into the activity log .. you may need to update work_notes or comments field of the table. Also try to copy attachments using GlideSysAttachment().copy() function.


Try to add following line of code and check



gr.work_notes = email.body ;             //copy email body to activity


GlideSysAttachment.copy('sys_email', email.sys_id.toString(), gr.getTableName(), gr.sys_id.toString());               //copy Attachments


Hello,


updating work notes (or comments field) to email.body content shows an additional line in "Activity" field (but not with standard mail contents with "plus" sign): com.glide.notification.inbound.EmailWrapper@1b86aa3.




As for the attachment copy - We can't copy it in that place. The reason for the script to be against "sys_data_source" table is that we have to attach an xls file from that mail to a new data source record, update our schedule import to point to that data source and execute it. And as we now the attachment is tied to the first record the inbound action produces. The problem is, when there is an attachment - we load the data (multiple lines) into another table, let's call it "my_target_table_2". And then with a business rule on that table we create a single record in "my_target_table" and connect those by setting a "parent" number. It could sound a bit complicated but those are requirements that we have, and it has to be done in that way.



But me question is, what does copying attachment have to do with showing emails in the activity log? Is this connected somehow?