Schedule a script to run as a specific user.
Can be used to avoid "System" updating a record, when you know which user actually updated. Example usage:

var ssa = new ScheduleScriptAs('myScriptName');
ssa.setRunAs('USER_SYS_ID');
ssa.setScript('SCRIPT_TO_RUN');
ssa.runSecondsLater(10); //Add delay
ssa.schedule();

Script include:
var ScheduleScriptAs = Class.create();
ScheduleScriptAs.prototype = {
    initialize: function(name) {
		this.active = 'true';
		this.name = 'Run ScheduleScriptAs ' + name;
		this.run_type = 'once';
		this.run_start = new GlideDateTime();
		this.script = '';
		this.run_as = gs.getUserID();
		this.sys_name = this.name;
		this.sys_class_name = 'sysauto_script';
		this.runSecondsLater = 0;
    },
 
	runSecondsLater: function(seconds) {
		this.runSecondsLater += seconds;
		this.run_start = new GlideDateTime(this.run_start);
		this.run_start.addSeconds(seconds);
	},
 
	setRunAs: function(user_sys_id) {
		this.run_as = user_sys_id;
	},
 
	setScript: function(script) {
		this.script = script;
	},
 
	schedule: function() {
		var s = new GlideRecord(this.sys_class_name);
		s.initialize();
		s.active = this.active;
		s.name = this.name;
		s.run_type = this.run_type;
		s.run_start = this.run_start;
		s.script = this.script;
		s.run_as = this.run_as;
		s.sys_name = this.sys_name;
		var s_id = s.insert();
		this._deleteSchedule(s_id);
	},
 
	_deleteSchedule: function(sys_id) {
		gs.sleep(10000 + this.runSecondsLater); //Allow schedule to be run
		var s = new GlideRecord(this.sys_class_name);
		if(s.get(sys_id)) {
			s.deleteRecord();
		}
	},
 
 
    type: 'ScheduleScriptAs'
};


If you have ever been in a situation where you or someone else has clicked on the "Track in update sets" related link, then you seem to be stuck with it, and you keep tracking any updates to these records on the table.

In order to disable it, you need to run the below script as a Background Script. Of course you need to replace the TABLE_SYS_ID with your actual sys_id of the table you want to change.

doNotTrackInUpdateSets();
function doNotTrackInUpdateSets() {
	var gr = new GlideRecord('sys_db_object');
	gr.addQuery('sys_id', 'TABLE_SYS_ID'); // Replace TABLE_SYS_ID with your tables sys_id
	gr.query();
	while(gr.next()) {
		gr.super_class = '';
		gr.setWorkflow(false);
		gr.update();
	}
}


Knowledge16 was big, geeky, and amazing. We participated in the precon training for App Creation and are now CERTIFIED APPLICATION DEVELOPER, besides that our main focus for the conference was the new ServicePortal, AngularJS, integrations and custom applications, which goes well with our expertise.
I have to say the ServicePortal is impressive, in what you can design and develop, but lacking in many core aspects as soon as you go slightly beyond basic features. It seems they were forced to release it now, since it was already postponed once, but I hope they will catch up soon tho.
The CreatorCon was really good, when things got a bit more technical.

Thanks everyone for a great experience! Looking forward to seeing you all at Knowledge17 next year in Orlando.

We are getting ready for Knowledge16, the ServiceNow conference of the year in Las Vegas.

"Experience the service revolution at Knowledge16 — where thousands of transformational leaders from every corner of the enterprise gather to share and discover how to unleash the power of a future fueled by service. Together, we will change the way people work and accelerate enterprise velocity to levels never thought possible. Because in revolutionary times, business as usual is no longer an option."
Read more about it on knowledge.servicenow.com

Hope to see you there? ;-)

We all know and use GlideRecord.update() and GlideRecord.insert(), but sometimes we would like to do a little more than that, we would like to insert or update data in reference fields as well, now instead of creating a new query to get and update these fields, ServiceNow have created these two wonderful functions to deal with this issue.

There are a few things to take note of when using these methods.
Firstly that the related records are updated first and then the actual record afterwards.
Secondly you need to keep in mind, that if a related record does no exist, one will be created. (In the below sample code, if there are no caller, it will create one with the information provided in the script).
Also if you need to set the value of a reference field on the record, you must set it using the .setDisplayValue() method before manipulating the reference field's values.
Lastly remember to use these methods carefully, as it will update multiple tables at once, if that is what you tell it to do.

GlideRecord.updateWithReferences()

var inc = new GlideRecord('incident');
inc.get(sys_id); //Get incident record based on the sys_id
inc.caller_id.first_name = 'Jesper';
inc.caller_id.email= 'jesper@not-a-real-email.com';
inc.updateWithReferences();

GlideRecord.insertWithReferences()
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = 'My printer is broken';
inc.caller_id.setDisplayValue('Jesper Testuser'); //Note that if we did not include this line to set the value, a new user would be created
inc.caller_id.first_name = 'Jesper';
inc.caller_id.email= 'jesper@not-a-real-email.com';
inc.insertWithReferences();
Read more about these functions at the ServiceNow Wiki


ServiceHow.com is now launched as an independent ServiceNow resource for admins and developers.
To assist and be helpful in ways that make life as a ServiceNow developer easier, more efficient and improve upon code quality by following best practices, performance and security optimizations.
Resulting in better developers, optimized and more secure code, improved ServiceNow instances and thereby more efficient businesses.

Top Cheat Sheets

About

ServiceHow.com's aim is to be a helpful resource for ServiceNow Developers. ServiceHow.com is not affiliated with ServiceNow.