Skip to content

Instantly share code, notes, and snippets.

@asimpkin
asimpkin / export_xml.js
Created March 22, 2024 22:50
ServiceNow background script to export multiple tables and append to a task as an .XML attachment.
// run in background here: now/nav/ui/classic/params/target/sys.scripts.do
// started from: https://www.servicenow.com/community/developer-forum/use-script-to-export-records-to-xml/m-p/2571773
// all credit to Riya Verma: https://www.servicenow.com/community/user/viewprofilepage/user-id/199367
// This will NOT get any attachments for the record.
// Define the tables you want to export records from
var tablesToExport = ['rm_epic', 'rm_story'];
// var tablesToExport = ['rm_epic']; // test with one table
@asimpkin
asimpkin / Inbound Email Action - Create Story.xml
Created February 16, 2024 00:22
ServiceNow - Inbound Email Action - Create Story
<?xml version="1.0" encoding="UTF-8"?>
<unload unload_date="2024-02-16 00:10:43">
<sysevent_in_email_action action="INSERT_OR_UPDATE">
<action>record_action</action>
<active>true</active>
<assignment_operator/>
<condition_script/>
<description/>
<event_name>email.read</event_name>
<filter_condition table="sys_email">subjectSTARTSWITHNEWSTRY|^EQ<item goto="false" or="false" field="subject" endquery="false" value="NEWSTRY|" operator="STARTSWITH" newquery="false"/>
@asimpkin
asimpkin / Update epics percent complete.xml
Created February 2, 2024 22:28
ServiceNow - Business Rule - rm_story - update epics percent complete
<?xml version="1.0" encoding="UTF-8"?>
<unload unload_date="2024-02-02 19:57:18">
<sys_script action="INSERT_OR_UPDATE">
<abort_action>false</abort_action>
<access>package_private</access>
<action_delete>false</action_delete>
<action_insert>true</action_insert>
<action_query>false</action_query>
<action_update>true</action_update>
<active>true</active>
<?xml version="1.0" encoding="UTF-8"?>
<unload unload_date="2024-01-26 17:59:29">
<sys_ux_style action="INSERT_OR_UPDATE">
<name>Camo</name>
<style>{
"isCamo": "true",
"base": {
"--now-color--neutral": "48, 80, 54",
"--now-color--primary": "48, 80, 54",
"--now-color--secondary": "48, 80, 54",
/*
https://www.servicenow.com/community/developer-articles/migrate-data-from-one-instance-to-another/ta-p/2303331
Migrate Data from one instance to another
https://www.linkedin.com/in/raymond-estevao-31722619/
Raymond Estevao
*/
var ThrottleLimit = 50; //2 sec
@asimpkin
asimpkin / getXMP.php
Last active November 6, 2019 00:49
PHP function to query ServiceNow REST API to GET a list of records from a table.
<?php
date_default_timezone_set('America/Los_Angeles');
DEFINE("INSTANCE","instancename");
DEFINE("SITE", "http://".$_SERVER['SERVER_NAME']); // ENABLE THIS LINE WHEN PUSHED TO PROD
DEFINE("USER","username");
DEFINE("PASS","password");
function getXML($table,$query) {
@asimpkin
asimpkin / GetICBCAgentsForCompany.js
Created January 18, 2017 20:10
ServiceNow Reference Qualifier - Simple for ICBC Agents to Companies
//Reference Qualifier Script to ensure users can only agents asscoaited with their own company
//SysID for Yoru Company : lfdkjslkajfsdlkajldkjalkdsjlkjadsljk
//If users matches your compamy then allow all agents
function GetICBCAgentsForCompany(company) {
var answer = ' ';
if (company != 'lfdkjslkajfsdlkajldkjalkdsjlkjadsljk'){
var agent = new GlideRecord('u_icbc_agent');
agent.addQuery('u_company',company);
agent.query();
@asimpkin
asimpkin / create_checklist_from_UI_action.br
Created December 23, 2016 00:25
Business Rule to create checklist and items from a given template into a task record
/*
The following business rules have been disabled to prevent worknotes from checklist/item changes
https://central1.service-now.com/sys_script_list.do?sysparm_query=GOTOnameLIKECRUD
*/
// Get the template data with the checklist items
var gr = new GlideRecord('checklist_template');
gr.get('dcc0b5e6373fa200afb4d02783990ef5'); // TEST TEMPLATE
var json = JSON.parse(gr.template);
@asimpkin
asimpkin / read_attachment_into_task.wf
Created September 6, 2016 17:42
ServiceNow workflow script to read a TASK attachment and put the comments into a JSON format within the task.
var tableName = 'sc_req_item';
var sysIDOfRecord = current.sys_id;
//Declare a new instance of GlideSysAttachment.
var gsa = new GlideSysAttachment();
//Get the raw bytes in the file
var bytesInFile = gsa.getBytes(tableName, sysIDOfRecord);
//Convert that jive into a string using Java/Rhino.
var dataAsString = Packages.java.lang.String(bytesInFile);
//Re-convert to a string in Javascript, cause we don't trust Rhino.
csv = String(dataAsString);
@asimpkin
asimpkin / jira_curl_post_test.php
Last active November 6, 2019 00:45
jira_curl_post_test
<?php
DEFINE("USER","USERNAME");
DEFINE("PASS","PASSWORD");
DEFINE("INSTANCE","INSTANCE");
//$URL = 'https://jira.URL.com/jira/rest/api/2/issue/createmeta';
$URL = 'https://jira.URL.com/jira/rest/api/2/issue/';
/*
$query=urlencode($query);