Skip to content

Instantly share code, notes, and snippets.

@Litwilly
Forked from icerge/features_unsorted.md
Created February 4, 2020 18:56
Show Gist options
  • Save Litwilly/5cf06e5dbd98ec0711cbf4b769a7aa23 to your computer and use it in GitHub Desktop.
Save Litwilly/5cf06e5dbd98ec0711cbf4b769a7aa23 to your computer and use it in GitHub Desktop.
Unsorted features of ServiceNow

Workflow column renderer

/column_renderer_list.do It is based on ui_macro.

Ajax - request source

...
this.getParameter('x-referer');

The value is a URL the request is coming from.

Dictionary utils

GlideTableDescriptor - mostly closed.

SNC.TableEditor

SncTableEditor

TableDrop SI?

GlideDBObjectManager (TableUtils wraps it).

GlideTableCleanupAPI.cleanupHierarchicalData(tableName);

GlideDBUtil

GlideDBUtil.promoteColumn(sourceTable, targetTable, column, promoteCheck)
/* 
Moves (promotes) a column from one table to another in the table hierarchy, optionally verifying the relationship between source and target tables.
If the move is a promotion, this will move all columns from the child tables that have the same column name as the target column name.
Otherwise, it will only move the column from the source table to the target table.
    * @param sourceTable (string) - The table currently containing the column to be promoted.
    * @param targetTable (string) - The table that will have the column after promotion.
    * @param column (string) - The column to be promoted.
    * @param promoteCheck (boolean) -  This method should verify that the source table is a child of the target table.

Stats.do

https://community.servicenow.com/community/service-automation-platform/blog/2017/07/06/just-another-statistic

Icons in ServiceNow

/styles/retina_icons/retina_icons.html

JOIN condition in GlideRecord query

This syntax is allowed to supply JOIN condtion for a query. Source is AssociateCIToTask script include.

existingCI.addQuery('JOINtask.sys_id=task_ci.task');

Usage of GlideOverlay

onAfterClose onAfterLoad

/* URL composition
		var url = new GlideURL("task_add_affected_cis.do");
		url.set("sysparm_crSysId", chgReqId);
		url.set("sysparm_view", "associate_ci");
		url.set("sysparm_add_to", addToTable);
		url.set("sysparm_stack", "no");
		url.set("sysparm_table", latestClassAdded);
		url.set("sysparm_parent_class", parentClass);
*/
///-----
var cmdbciOverlay = new GlideOverlay({
	id : "cm_add_affected_cis",
	title : getMessage("Add Affected Configuration Items"),
	iframe : url,
	closeOnEscape : true,
	showClose : true,
	onAfterClose: refreshAffectedCIs,
	onAfterLoad: resizeIframe,	//Once PRB632264 is fixed by platform we can comment this line
	height : "90%",
	width : "90%"
});

Updating datetime field

There is no need to instantiate a separate GlideDateTime object using constructor. Use GlideElement reference and getGlideObject() method.

current.opened_on.getGlideObject().addYearsUTC(1);

Notifications from Parent table don't run for child table.

Yes, it's true. Most probably, because notifications trigger based on events (event Insert/Update notification). Even processing doesn't consider table hierarchy.

Client side code sharing

This trick works. I define a utility class in one onload script and use it in others.

/* Client script on order 10. */
function onLoad() {
	/* Loading utility client functions for Change request */
}

function ChangeClientUtils() {
	
	this.isInPast = function(dt) {
		if(!dt) {
			// no field value
			return false;
		}
		
		var x = getDateFromFormat(dt, g_user_date_time_format);
		var now = Date.now();
		return x < now;
	};
	
	this.isGoLiveStartInPast = function() {
		return this.isInPast(g_form.getValue('start_date'));
	};
	
	this.isGoLiveEndInPast = function() {
		return this.isInPast(g_form.getValue('end_date'));		
	};
	
	this.isStartEndInSequence = function() {
		var s = getDateFromFormat(g_form.getValue('start_date'), g_user_date_time_format);
		var e = getDateFromFormat(g_form.getValue('end_date'), g_user_date_time_format);
		return s < e;
	};
	
	this.isRetrospective = function() {
		return g_form.getBooleanValue('u_retrospective');
	};
	
	this.isEmergency = function() {
		return g_form.getValue('type') == 'Emergency';
	};
	
}

Get field choices (GlideChoiceListGenerator)

Noticed in OOTB: sp_widget.do?sys_id=cb6631d39f2003002899d4b4232e7030

var x = new GlideChoiceListGenerator('incident', 'state');
var c = x.get();
gs.print(c);
>> [New : 1, In Progress : 2, On Hold : 3, Resolved : 6, Closed : 7, Canceled : 8]

And here is the list of remarkable attributes:

  • activeOnly
  • setActiveOnly
  • inactiveOnly
  • setInactiveOnly
  • dependentValue
  • setDependentValue
  • recordList
  • getRecordList
  • none
  • setNone
  • cache
  • setCache
  • get
  • scripted
  • isScripted
  • all
  • setAll
  • extensions
  • setExtensions
  • choiceList
  • getChoiceList

When jobs are running long in Schedules (sys_trigger)

...and, for example, Update Set retrieval is queued forever

a. Go to /v_cluster_transaction_list.do, refresh (UI Action link), locate the oldest job and kill it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment