Display Email Log in a related list

Victor Ruiz
Tera Guru

How can I Display Email Log in a related list on INC?

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

The sys_email table uses a Document ID field(s) to relate back to records, not a direct relationship.   So you will need to create a user defined related list:


Creating Defined Related Lists - ServiceNow Wiki


1. Go to System Definition\Relationships and click New


2. Name what you want to call this related list in the Name field- example "Email Log"


3. In applies to table choose incident - or if you want this to all tasks you can choose task


4. In queries from table choose Email


5. In the query with script field, paste in:


(function refineQuery(current, parent) {



      current.addQuery("target_table", parent.sys_class_name);


      current.addQuery("instance", parent.sys_id);



})(current, parent);


6. Click Submit.


7. Go to your incident form, configure related lists, and add "Email Log" or whatever you called the relationship in step 2 above.


View solution in original post

10 REPLIES 10

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

The sys_email table uses a Document ID field(s) to relate back to records, not a direct relationship.   So you will need to create a user defined related list:


Creating Defined Related Lists - ServiceNow Wiki


1. Go to System Definition\Relationships and click New


2. Name what you want to call this related list in the Name field- example "Email Log"


3. In applies to table choose incident - or if you want this to all tasks you can choose task


4. In queries from table choose Email


5. In the query with script field, paste in:


(function refineQuery(current, parent) {



      current.addQuery("target_table", parent.sys_class_name);


      current.addQuery("instance", parent.sys_id);



})(current, parent);


6. Click Submit.


7. Go to your incident form, configure related lists, and add "Email Log" or whatever you called the relationship in step 2 above.


You know, perhaps it's just slop-programming on my part     or maybe it's an intended/built-in efficiency of using Document ID fields... but I think you can safely leave out the 'target_table' part of your query if only you can rely on a sys_id never being repeated within an instance.



And that's pretty much guaranteed here("The same sys_id value will never be generated twice,..."):


Unique Record Identifier - ServiceNow Wiki



It may not matter in a simple query such as this one, but it can be quite helpful to require specification of which table something belongs to when your query is a bit more complex.   For me, this was handy when addressing a consolidated attachments list ala this other post:


Display parent attachments in sc_task




-Brian


Hi Thanks Michael, this is great! But this seems to make the page too slow. 
Because it queries almost all the emails and then fetches me the necessary ones. Is there a better way or place to write this query? 
SO that the page does not get slow. 
@Michael Ritchie 

For this same configuration https://community.servicenow.com/community?id=community_question&sys_id=165f72a9db58dbc01dcaf3231f961984

How to use it for the mobile application.

For example, consider the Cases,

This cases contains Emails in the related list tab( currently we have this functionality in Agent Workspace) how to implement the same functionality for Now agent mobile app. So that the app contains icon for cases and inside the cases we must have the email tab as related list.....

How to configure this using studio......how to implement the related list part...... currently Email is not showing under the related list (relationship), if we search there and destination screen