input - fdlGitHub/ServiceNow GitHub Wiki

new GlideDate().getByFormat('yyyy-MM-dd HH:mm:ss.SSS')

System Property

gs.setProperty('property_name', property_value);
GlideProperties.getBoolean('glide.discovery.debug.ci_identification', false);
GlideProperties.getInt('glide.email_diag.threshold.smtp_sender.runtime', 10000);
GlideProperties.get("glide.approval.delegation.version", "v1");

Cache Manager

GlideCacheManager.get('syscache_sys_certificate', 'sys_certificate_cache_key'));
GlideCacheManager.flush("syscache_sys_certificate");

Scheduler Workers

gs.pause();
gs.resume();

GSLog

System Property Choice list
Choices: Emergency=emerg, Alert=alert, Critical=crit, Error=err, Warning=warning, Notice=notice, Info=info, Debug=debug

var log = new global.GSLog('system_property_name', 'Source');
log.includeTimestamp();

Scheduled import

var gdt = new GlideDateTime();
var date = gdt.getDate();

var morning = new GlideDateTime();
var evening = new GlideDateTime();

morning.setDisplayValue(date + " 05:00:00");
evening.setDisplayValue(date + " 22:00:00");

if(gdt.getDayOfWeekLocalTime() == 6 || gdt.getDayOfWeekLocalTime() == 7) {
// Week-end
answer = false;
}
else {
if(gdt.compareTo(morning) != 1 ||  evening.compareTo(gdt) != 1) {
	// Night
	answer = false;
}
}






var attachmentGSA = new GlideSysAttachment();

sysAttachmentGR = new GlideRecord('sys_attachment');
sysAttachmentGR.addQuery('table_name', 'x_74897_tkt_tpl_configuration');
sysAttachmentGR.addQuery('table_sys_id', 'b42846b0db88030044edd421cf96191f');
sysAttachmentGR.orderBy('sys_created_on');
 sysAttachmentGR.query();
 if(sysAttachmentGR.next()) {
gs.debug(attachmentGSA.getContent(sysAttachmentGR));
 }




setIncidentHistory: function(caseGR, incidentGR) {
	// Sync Activity Logs
	var caseHistoryLineGR = '';
	var incidentHistoryLineGR = '';

	var incidentGHS = new GlideHistorySet(incidentGR.getTableName(), incidentGR.getUniqueValue()); 
	var incidentHistorySetID = incidentGHS.generate();

	var incidentHistorySetGR = new GlideRecord('sys_history_set');
	if(incidentHistorySetGR.get('id', incidentHistorySetID)) {
		incidentHistorySetGR.updates = caseGR.sys_mod_count;
		incidentHistorySetGR.setWorkflow(false);
		incidentHistorySetGR.autoSysFields(false);
		incidentHistorySetGR.update();
	}

	// Step 1: Delete the current History Line of Incident
	incidentHistoryLineGR = new GlideRecord('sys_history_line');
	incidentHistoryLineGR.addQuery('set', incidentHistorySetID);
	incidentHistoryLineGR.deleteMultiple();

	// Step 2: Copy the History Line of the Case into the History Line of the Incident
	caseHistoryLineGR = new GlideRecord('sys_history_line');
	caseHistoryLineGR.addQuery('set.id', caseGR.sys_id);
	caseHistoryLineGR.addQuery('field', 'comments');
	caseHistoryLineGR.query();
	while(caseHistoryLineGR.next()) {
		caseHistoryLineGR.set = incidentHistorySetID;
		caseHistoryLineGR.setWorkflow(false);
		caseHistoryLineGR.autoSysFields(false);
		caseHistoryLineGR.insert();
	}
},




function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

//Avoid reopening pop up when the affected service is set by the template functionality
    if (g_form.getValue('u_template') != ''){
    return;
    }

    // Give time to the Client Script: '(SCM) Set Account & Scratchpad' to finish ('Order' only controls the start order)
    window.setTimeout(checkIfAnyTemplateAvailable, 1000);	
}


function checkIfAnyTemplateAvailable(){
//Check if there is any template available
    var ga = new GlideAjax('global.GlideTemplateAJAX');
    ga.addParam('sysparm_name', 'getIfTemplatesAvailable');
    ga.addParam('sysparm_account', g_form.getValue('account'));
    ga.addParam('sysparm_u_affected_service', g_form.getValue('u_affected_service'));
    ga.addParam('sysparm_category', g_form.getValue('category'));
    ga.addParam('sysparm_subcategory', g_form.getValue('subcategory'));
    ga.getXML(openReferenceList);
}


function openReferenceList(response){
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer != '0'){
        //Open reference list
        var tbl = g_form.getTableName() + '.u_template';
        var tblDisp = 'sys_display.' + tbl;
        var e = gel(tblDisp);
        if (!e.ac){
            new AJAXReferenceCompleter(e, tbl, 'null', 'true');
        }
        reflistOpen(tbl, 'u_template', 'u_ticket_template', 'null', 'false', 'true');
    }
}

// Step 2: Generate the History of the current record (to be able to copy it in the incident) // GlideHistorySet not allowed in the Application Scope //new GlideHistorySet(current.getTableName(), current.getUniqueValue()).generate();

		g_form.setSectionDisplay('itsmscs', true);
		g_tabs2Sections.setActive(g_tabs2Sections.findTabIndex('u_scs_op_cat_1'));


var emailDiag = new global.EmailDiagnosticsV2();
gs.print('isSendingOperational: ' + emailDiag.isSendingOperational());
gs.print('isReceivingOperational: ' + emailDiag.isReceivingOperational());
gs.print('emailReaderLastRun: ' + emailDiag.emailReaderLastRun);
gs.print('smtpSenderLastRun: ' + emailDiag.smtpSenderLastRun);
gs.print('receivingEnabled: ' + emailDiag.receivingEnabled); 
gs.print('sendingEnabled: ' + emailDiag.sendingEnabled);
gs.print('lastReceived: ' + emailDiag.lastReceived);
gs.print('lastSent: ' + emailDiag.lastSent);
gs.print('getSendReadyCount: ' + emailDiag.getSendReadyCount());


	var ldapDiag = new GlideLDAPDiagnostics(ldap_id);
	return ldapDiag.loadDiagnostics();
var ldap_id = "${RP.getWindowProperties().get('ldap_server_id')}";
var json = eval("(" + answer + ")");

var lastMessage = json['glide.ldap.listener' + '-' + ldap_id];
var activeStatus = json['glide.ldap.listener' + '-' + ldap_id + '.active'];
var shutdownPending = json['glide.ldap.listener' + '-' + ldap_id + '.shutdown_pending'];
var starting = json['glide.ldap.listener' + '-' + ldap_id + '.starting'];
var lastChange = json['glide.ldap.listener' + '-' + ldap_id + '.last_change'];
var lastError = json['glide.ldap.listener' + '-' + ldap_id + '.last_error'];