ServiceNow tips
Logging
gs.info("JJJJ " + JSON.stringify(taskCreate));
Default columns
Go to List Layout
Script to pad out a number to 7 digits
var z ='';
var x = 10;
var gr = new GlideRecord("alm_hardware");
//gr.setLimit(20);
gr.query();
while (gr.next()){
x++;
z = padDigits(x, 7);
z = "R" + z;
gr.asset_tag = z;
gr.update();
//gs.print (z);
}
gs.print("DONE");
function padDigits(number, digits) {
return Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number;
}
Quick way to get GlideRecord
var grpRec = new GlideRecord('sys_user_group');
grpRec.get(current.group);
var grpMgr = grpRec.getValue('manager');
if (grpMgr != gs.getUserID()) {
current.setAbortAction(true);
gs.addErrorMessage('You must be a Group Manager to add members');
}
var msg = gs.getMessage('Hello');
gs.addInfoMessage(msg);
Dates
Get the last day of the month:
var lastday = getDaysInMonth(1, 2022);
function getDaysInMonth(m, y) {
return m===2 ? y & 3 || !(y%25) && y & 15 ? 28 : 29 : 30 + (m+(m>>3)&1);
}
Translated text
ServiceNow Localization & Language Translation Explained (youtube.com) (See at 6 mins how to find out which table is used. It works by showing the PREFIX)
sys_translated_text.list
sys_translated.list
sys_translated_text.list
sys_translated.list
sys_documentation.list (Field Labels. Language:en)l
sys_ui_message_translations.list
sys_ui_message.list
sys_choice.listk
sys_choice.listk
SERVER SIDE
data.message = gs.getMessage("this message contains 'quotes'");
Check that the language Plugin is installed
--> Here are the translations of texts. If you have a hardware model you will have an entry where "Table Name=Hardware Model [cmdb_hardware_product_model]"
--> If the Hardware Model is published in the cat item there will also be an entry for the same item where "Table Name=Hardware-Katalog [pc_hardware_cat_item]"
--> It should be that when the "Description" of the Hardware Model is updated it will automatically update the "Description" in the cat item. However, for some reason to be discovered later it doesnt work!
vargr = newGlideRecord('sys_ui_message');
gr.addQuery('language', 'en');
gr.addQuery('key', 'Busylight FREE software');
gr.addQuery('code', 'short_description');
gr.query();
while(gr.next()) {
// Do something with the record}
}
Related Lists
To change the name of a label of Related List:
- sys_translated_text.list
- Table Name= Relationship [sys_relationship]
- Document= e.g. Relationship: Benefit Plans
- Change the Value
See also sys_documentation.list -> This has the label translations
Also check out sys_ui_message_list
How to add a hyperlink
Have a field which is of String
Create a Client Script and add the following:
onLoad and UI type: All
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('u_psp_element')){
g_form.setReadOnly('u_psp_element',false);
g_form.getControl('u_psp_element').style.color = 'blue'; // Set text font color to blue
g_form.getControl('u_psp_element').style.textDecoration = "underline"; // Set text decoration to underlined
g_form.getControl('u_psp_element').style['box-shadow'] = "none"; //remove shadow
g_form.getControl('u_psp_element').style['-webkit-box-shadow']="none"; //remove shadow
g_form.getControl('u_psp_element').style.border= '0px';
g_form.getControl('u_psp_element').onmouseover = mouseOver; // Set mouseOver cursor style
g_form.getControl('u_psp_element').onclick = urlFunction; // Set onclick to the redirect url
}else{
g_form.setReadOnly('u_psp_element',true);
}
}
function mouseOver() {
// this.style.cursor = 'hand'; // Set onmouseover cursor style
this.style.cursor = 'pointer';
}
function urlFunction() {
var ga = new GlideAjax('BS_Task');
ga.addParam('sysparm_name', 'getTaskUrl');
ga.addParam('sysparm_src_sysid', g_form.getValue('task'));
ga.getXML(appendDefault);
function appendDefault(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert (answer);
top.window.open(answer);
}
}
Related Lists
sys_ui_related_list
Demands
The value in the category field determines the values available in the type field. And the type field determines what record type you can promote the demand to.
- If the demand is something that will support "keeping the lights on" - it is considered operational. If you select the category of operational you will only be able to promote the demand to a change or defect.
- If the demand is an effort working toward a strategic goal of the organization - it is strategic. If you select the category of strategic you will only be able to promote the demand to an enhancement, project, epic or story.
Global Search doesnt return a result
- Go to table: ts_group.list ("Text Search Groups")
- Open up "Tasks" and "pm_project" and "pm_project_task" to the "Text Search Tables"
HTTPS and how it works
Used to verify you are connected to the right website.
PKI - Public Key Infrastructure - Is a framework used to encrypt data between client and server.
X.509 is an SSL Certificate
CA - Certification Authority which validates the Certificate.
1. Go to any website that says https.
2. The Server returns a Public Key which has been signed by the CA Authority
3. The browser checks that the Certificate hasn't expired and that it is related to the website you are requesting
4. If the Certificate passes, the browser generates a Random Symmetric Key and uses it to encrypt the request address, plus some other data.
The browser using the Public Key to encrypt the whole thing and sends to the web server.
6. The web server uses the private key to decrypt the payload and so retrieves the Symmetric key.
It then uses the Symmetric Key to decrypt the extra information. i.e. request URL and extra data
7. From this point both the browser and web server will use the Symmetric key to encrypt data before sending it and decrypt it when it arrives
SSO
Used to identify User!
Comprises of 3 Entities:
User
Identity Provider (IDP)
Service Provider
Protocols used by SSO:
Basic Auth - simple username and password.
- It may be that its verifying the user with the IDP.
OAuth - API security model that relies on an outside Identity Provider and key-store to grant and deny access to APIs
- The user tries to log in and it goes and get a key from the IDP. The IDP sends back a Token (known as a key). Using this key the User logs into the Service Provider.
- Service Provider will validate the token(key) with the IDP
SAML
- a web based model that allows a third party application or service to validate the users identity and retrieve details about the user (XML based)
- SAML 2.0 is an XML-based open standard protocol for exchanging authentication and authorization data. It uses security tokens with assertions to securely pass information about a user's identity from an Identity Provider (IdP) to a Service Provider (SP)
- Security Assertion Markup Language (SAML)
- IDP -> Service Provider
What is an IDP
It has a combination of these 3 things:
-User Information
-Organisational Information
-Application/SP Information
try catch throw finally
try {
if(x == "") throw "is Empty";
if(isNaN(x)) throw "not a number";
if(x > 10) throw "too high";
if(x < 5) throw "too low";
if(isNaN(x)) throw "not a number";
if(x > 10) throw "too high";
if(x < 5) throw "too low";
instanceMapping = JSON.parse(gs.getProperty('fen.integration.jira.instanceMapping') +'');
if(!gs.nil(accessibleRoles) && !gs.getUser().hasRole(accessibleRoles)) {
throw new Error(ADTConstants.ERR_MSG_DIAG_UNAUTHORIZED_ACCESS);
}
} catch(e) {
this.lastError = 'Loading instance mapping failed:\n'+ JSON.stringify(e, null, '\t');
gs.error("Error occured while deleting Message Auth " + e.message);
gs.info(e);
- Both
catchandfinallyare optional, but you must use one of them. - Only use them when you expect an exception to occur and you need to handle it in a specific way.
- ServiceNow is expecting an Error object in a throw. This is the simplest way to throw an error with a message:
OAuth
- It stands for "Open Authorization".
- OAuth 2.0 is an authorization protocol and NOT an authentication protocol. (Authentication is a process that verifies your identity.)
- As such, it is designed primarily as a means of granting access to a set of resources, for example, remote APIs or user data.
- OAuth 2.0 uses Access Tokens to prove your identity and allow it to interact with another service on your behalf..
- Access tokens are what make OAuth secure to use.
- An access token is a piece of data that contains information about the user and the resource the token is intended for. A token will also include specific rules for data sharing.
- OAuth is designed to work with Hypertext Transfer Protocol (HTTP).