Giter VIP home page Giter VIP logo

sntil's People

Contributors

iamkalai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sntil's Issues

glide.security.admin.override.accessterm

When 'glide.security.admin.override.accessterm' is false, ACLs are evaluated cumulatively. If there are number of ACLs on any given field and the Admin Overrides option is false (not selected) on one of them, then the effective admin overrides for all the ACLs are considered to be false. This causes admins to be unable to pass even the ACL where the override should be in effect.

Credits: Chaithanya Bontha

Computer-Instance Connection Speed

If you want to know the connection speed between your computer and your instance, you can do so by visiting the below URL.

yourinstance/connection_test.do

Credit: @WoZ

Find Record Producer That Created Record

If you want to find which record producer created a record in ServiceNow, look into sc_item_produced_record table.

Note that if the target record is a task, it'll show up in the task field of the table. If it's not a task (and also if it is), then you can find the record using the value of the record_table field and the record_key field.

Empty Object Check

While JSUtil.notNil is awesome, do keep in mind that it does not work for empty object. Use JSUtil.isEmpty for checking objects.

Sample:
gs.print("This does not work for object JSUtil.notNil({}):"+JSUtil.notNil({}));
gs.print("This works for empty object JSUtil.isEmpty({}):"+JSUtil.isEmpty({}));

var obj = {a:1};
gs.print("Not a empty object JSUtil.isEmpty(obj):"+JSUtil.isEmpty(obj));

evil of toString()

The evil of toString() - "Regex strikes back"

Spent few hours tracking this down as Replace method won't support regex for objects. What a fun Friday this was.

Simplified code:

var uri = gs.action.getGlideURI()
var object = uri.toString();
var string = uri+"";

gs.print(uri);
//gs.print(object.replace(/sys_scripts/,'')); //throws an error.
gs.print(string.replace(/sys.scripts/,''));

gs.print(typeof object);
gs.print(typeof string);

gs.getProperty is faster

gs.getProperty is faster than an equivalent gliderecord.

var stopwatch1 = new GlideStopWatch();
gs.print(gs.getProperty(''));
gs.print('Timer:'+stopwatch1);

var stopwatch2 = new GlideStopWatch();
var gr1 = new GlideRecord('sys_properties');
gr1.addEncodedQuery('name=');
gr1.setLimit(1);
gr1.query();
if (gr1.next()) {
gs.print(gr1.getValue('value'));
}
gs.print('Timer:'+stopwatch2);

g_scratchpad On Portal

g_scratchpad works in catalog client script on portal but does not on normal UI.

if (typeof g_scratchpad != 'undefined') {
alert("Portal");
} else {
alert("Normal UI");
}

GlideAggregate default groupby

GlideAggregate groups by the aggregated column by default (when using functions MAX, MIN or AVG).
So don't forget to use its setGroup method.

Sample in comments section.
Credits: @jános Szentpáli

var cmn_location_Ga = new GlideAggregate('cmn_location');
cmn_location_Ga.addNotNullQuery('u_node_id');
cmn_location_Ga.addAggregate('MAX', 'u_node_id');
cmn_location_Ga.setGroup(false);
cmn_location_Ga._query();
if (cmn_location_Ga._next()) {
return +cmn_location_Ga.getAggregate('MAX', 'u_node_id');
} else {
return 0;
}

Client Callable Script Include With Initialization

While creating a client callable script include, the general practice is to avoid overriding initialize method, which is also stated in the official documentation.

https://docs.servicenow.com/bundle/orlando-application-development/page/script/ajax/topic/p_AJAX.html

But, in case you do want to override the initialize method for some reason, you can do so easily by following the below sample. You just need to add few extra parameters to your initialize method and invoke AbstractAjaxProcessor's initialize method.

//Sample script include
var DoStuff = Class.create();
DoStuff.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    initialize: function(request, responseXML, gc) {
        AbstractAjaxProcessor.prototype.initialize.call(this, request, responseXML, gc);
        this.stuff = 'something';
    },

    print: function() {
        return this.stuff;
    },
});```

//Sample script to test script include works
var glideAjax = new GlideAjax('DoStuff');
glideAjax.addParam('sysparm_name','print');
glideAjax.getXMLWait();
alert(glideAjax.getAnswer());

Report View Event

report.view event gets triggered by the platform whenever you view a report in ServiceNow. The event is also generated when the report is run via scheduled report.

GlideProperties.getBoolean()

gs.getProperty returns the property value as string irrespective of the type of property being accessed. But, if you are in global scope and want to return a property as 'Boolean', you can use GlideProperties.getBoolean() instead. Additionally, there is also a function GlideProperties.getInt() to return the property value as 'int'.

Credits: János Szentpáli

Apply Template Automatically

If you create a template (sys_template) with the same name as the table, the template gets applied automatically to all new records created for that table.

Ex: Create a template called 'incident' and try creating a new incident. The fields on the new incident are updated as per the template created.

Credits: Geo (sndevs slack).

Is Script Out Of Box?

A rough way of checking if something is out of the box is to check Upgrade history. If it is not in sys_upgrade_history_log, then it might not be from ServiceNow.

Credits: AJB

Flow Inline Script (fd_data object)

fd_data object is used to access information related to flow when inline scripting in a flow.

You can access the some step's output using fd_data._stepnumber.
You can access current record using fd_data.trigger.current.

View JSFiddle

You can view JsFiddle output in a separate tab by adding '/show' at the end of your fiddle.

Useless Client Script Field

There is a Condition/On Click field on Client script table. Per HI ticket, the field is not in use. There is no documentation because this was never usable.
So in essence, this is a ServiceNow meme "Don't know what it does but I am scared to delete"

Credits: ServiceNow Community Question.

Execute Script Asynchronously

If you want execute a script asynchronously or execute a script once, you can make use of ServiceNow's ScheduleOnce script. In the below script, you can replace the call of gs.log with any server side script call (like calling a function of some script include).

//Sample
var scheduleJob = new global.ScheduleOnce();
scheduleJob.script = "gs.log('Test Log','Adhoc')";
scheduleJob.setLabel("Adhoc Job");
scheduleJob.schedule();

Note: Will not work in scope.

GlideElement has String functions

GlideElement actually includes most of the String.prototype functions. Thus current.description.toUpperCase() for instance converts description to uppercase

Credits: János Szentpáli

Update Multiple Records - Flow

There are no action to directly query and update multiple records in flow designer. Use lookup action to find records. Chain it with 'For Each' and 'Update Record' action to process all the records.

Impersonate Functions

Below functions can be used
Impersonate - gs.getSession().impersonate(userID);
End Impersonation - gs.getSession().onlineUnimpersonate();

Broken Release Management OOB

Out of the box release management in ServiceNow is broken in its native form. When you save the state of a release or feature to Testing/QA, the active flag is set to false.

Revert Workflow

You can revert #ServiceNow workflow to any previous version Out of the box.

  • Go to the workflow record in the wf_workflow table.
  • Right click in the form header, go to 'Show File Properties'.
  • Add the 'versions' related list to the form if it's not already there.
  • Right click the version you want to revert to, click 'Revert to this Version'.
  • Click 'Ok' on the dialog, and the workflow is reverted.

Credits - Chris Sanford.

Get Next Number

Use the below to get the next number for a table
new global.NumberManager('tablename').getNextObjNumberPadded();

Gliderecord get() function second param

You may know that get() function can accept two arguments. When you pass two arguments, the first becomes the column for searching and the second is the value. But you should also know that get() can return multiple records based on the condition passed. So do not write your script under the assumption that get() will return only one record.

var incident = new GlideRecord('incident');
if (incident.get('caller_id', gs.getUserID())) { //This returns more than one record
gs.print(incident.number);
incident.next(); //You can iterate to next record like a normal gliderecord query
gs.print(incident.number);
}

Updateset Best Practice

For completed update set on the production instance, you should always change the state to Ignore. This state ensures that the update set is not committed again when cloning the instance.

Credits: Garrison Ball

Link Repo For Scoped App

If you want to relink your scoped app to a new repo, you have to delete the existing repo link for the app from sys_repo_config table. Deleting the existing link will allow you to use studio to add the new repo link.

glideUserSession

g_user object is not available for client scripts on service portal widget. You can instead use glideUserSession object to retrieve the same info.

Instance Nodes Info

The nodes that are assigned to your instance can be found from sys_cluster_state table.

Export VTB to XML

If you want to move VTB (Visual Task Board) from one instance to another, there is a OOB button 'Export Board to XML" on Visual Task Board (vtb_board) Table.

Credits: Jarod Mundt

Colourful console.log

Want colourful log messages? Use- console.log("%cTest", "font-family:arial;color:red;font-weight:bold;font-size:3rem");

Credits: (leirasanchez)

Find Instance Provision Details

If you ever need to find when your ServiceNow instance was provisioned, go to system properties and look at the updated date of the property instance_name or instance_id.

Open Module In New Window

If you want to open a left navigation menu in new window rather in the same window,

  • create a module of type URL (from Arguments:)
  • add some text in 'window name' field.

ref_qual_elements attribute

If you want lookup select variable dependent on some other variable, add ref_qual_elements attribute to the variable definition.
To add more than one dependent variables, separate them by ';'.

Ex: ref_qual_elements=variable1;variable2

Optional Gliderecord's update() Param

In case you did not know, Gliderecord's update() has an optional parameter which you can use to pass the reason for the update. The reason gets displayed (field-Reason) in Audit record (sys_audit).

Ex: .update('Test Update');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.