Adding Non-Task tables to the My Tickets widget in ServiceNow

You may find it odd that ServiceNow does not include the ability out of the box to include non-task related records in the My Tickets widget in the Service Portal.

One leading factor we believe is the cause of this exclusion, is the fact that your custom tables will not include the default set of fields that are being referenced in this widget, which leads to the logical exclusion of non-task tables as there is no guarentee that they will work appropriately.

However, should you still wish to show custom tables in this widget, we have a solution for you below.

Modify the My Tickets widget

Below we have referenced a block of code that you can replicate and modify in your ServiceNow "My Tickets" widget in order to show tickets that do not extend the Task table.

The general idea is that we extract the records we need and then build a data object that we push into the data.tickets object that already exists inside the widget.

Our example below works for the Interaction table (which is non-task), you can modify this to work for any table you desire.

// Initiate your glide record on the table of choice
var interactions = new GlideRecord("interaction");
	
// Query the specific records you require, in this case we are filtering using the "Dynamic Me" encoded query, given it is "My Tickets"
interactions.addEncodedQuery("opened_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe");

// Here we can honor the search strings placed in the widget and make it relevant to the table we are using
if (localInput && localInput.search_text) {
	interactions.addQuery('123TEXTQUERY321', localInput.search_text);
}

// We ensure that we only show active tickets if widget is set to open
if (localInput && localInput.view === 'open'){ 
	interactions.addQuery('active', 1);
  
// Or only inactive tickets if set to close
}else if (localInput && localInput.view === 'close'){
	interactions.addQuery('active', 0);
  
// Then set a default to active
}else{
	interactions.addQuery('active', 1);
}

// Then we run the query
interactions.query();

// We now itterate through the results
while(interactions.next()){
  
		// Look up the attached interaction record
	var interactionRelatedRecord = new GlideRecord("interaction_related_record");
    interactionRelatedRecord.addQuery("interaction",interactions.getValue("sys_id"));
		interactionRelatedRecord.query();
		if(!interactionRelatedRecord.next()){
          
			// Interaction has not been converted to another record
            // So we build an object with the relevant values and push it to data.tickets
			data.tickets.push({
				sys_id:interactions.getUniqueValue(),
				number:interactions.getValue("number"),
				title:interactions.getValue("short_description"),
				status:interactions.getDisplayValue("state"),
				created:interactions.getValue("sys_created_on"),
				url:{ id:'ticket', table: 'interaction', sys_id: interactions.getUniqueValue()}
			});
          
		}
  
	}

Server Script

A few key notes:

  • You will want to push your records to the data.tickets object that already exists
  • You will want your objects to contain the following values
    • sys_id
    • number
    • title
    • status
    • created
    • url