What the LOG object can do for you…

General Add comments

Recently a respected and very knowledgeable colleague of mine posted an article about finding specific information in the ServiceNow Wiki.
Wonderful, Wiki is a great source for information, but what if the specifics you are searching for are not available from Wiki?

Let me give you an example….

Wiki says the following:

Variable name Type Description Usage Example
log Function The log object for the current import run. For example,
log.info( STRING ),
log.warn( STRING ),
log.error( STRING )
log.info(“An error has occurred”)
log.warn(“An error has occurred”)
log.error(“An error has occurred”)

But what can the log object do more for you??

Well, check the following:

Method Type Description Usage Example
Function log.info(STRING msg, STRING source)
log.warn(STRING msg, STRING source)
log.error(STRING msg, STRING source)
log.info(“An error has occurred”, “SCCM”)
log.warn(“An error has occurred”, “SCCM”)
log.error(“An error has occurred”, “SCCM”)
Method Type Description Usage Example
Function log.rowInfo(STRING msg, STRING importRowId)
log.rowWarn(STRING msg, STRING importRowId)
log.rowError(STRING msg, STRING importRowId)

This links the log to the specified Import Row sys_id

log.info(“An error has occurred”, source.sys_id.toString())
log.warn(“An error has occurred”, source.sys_id.toString())
log.error(“An error has occurred”, source.sys_id.toString())
Method Type Description Usage Example
setImportSetRow Function log.setImportSetRow(STRING importRowID)

Set all future log entries to the specified Import Row sys_id.
Use this when your set log statements are not linked to your current import row. (e.g. Webservice and JDBC connections).

In the Transformap script use:
Method Type Description Usage Example
getImportRunHistory Function log.getImportRunHistory(STRING importRunID)

Get the current Import Run sys_id

Send the current Import Run as an argument to an event.
var script = ‘var sr = new SCCMSoftwareReconciler(“‘ +
computerGr.sys_id + ‘”,”‘ + id + ‘”,”‘ + import_set.sys_id + ‘”,”‘ + log.getImportRunHistory() +'”);’;
script += ‘\n’ + ‘sr.run();’;
Method Type Description Usage Example
setImportRunHistory Function log.setImportRunHistory(STRING importRowID)

Link the log to the specified import Run sys_id

Link the log to the specified Import RunSCCMSoftwareReconciler.prototype = {
initialize: function(computerSysID, swID, importSetID, importRunHistory) {
this.computerSysID = computerSysID;
this.swID = swID;
this.importSetID = importSetID;
this.log = new GlideImportLog(“SCCMSoftwareReconciler”);

This might just come in handy.
In case of any questions, you can contact me at .img[at].img.

Leave a Reply