iamkalai / sntil Goto Github PK
View Code? Open in Web Editor NEWServiceNow TIL (Today I Learned)
License: GNU General Public License v3.0
ServiceNow TIL (Today I Learned)
License: GNU General Public License v3.0
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.
If you want to open a left navigation menu in new window rather in the same window,
Want colourful log messages? Use- console.log("%cTest", "font-family:arial;color:red;font-weight:bold;font-size:3rem");
Credits: (leirasanchez)
Rather than omitting watermarks, it is possible to hide watermarks on a global basis.
Set glide.email.watermark.visible and set it to false.
You can view JsFiddle output in a separate tab by adding '/show' at the end of your fiddle.
g_user object is not available for client scripts on service portal widget. You can instead use glideUserSession object to retrieve the same info.
setWorkflow(false) does not stop flows from triggering in scoped apps.
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.
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
sp_rel_widget_clone holds the relationship from which the widget was cloned.
Use the below to get the next number for a table
new global.NumberManager('tablename').getNextObjNumberPadded();
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
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;
}
You can add your visual task board (VTB) to Dashboard using Iframes.
Credits: Adam Stout
FYI - https://community.servicenow.com/community?id=community_blog&sys_id=5b1edeb6db2604545ed4a851ca961968
The nodes that are assigned to your instance can be found from sys_cluster_state table.
If you want to make all the variables of a catalog readonly on RITM or sc_task table, you can use g_form.setVariablesReadOnly(true);
Note that this will not work on other tables like incident
https://hi.service-now.com/kb_view.do?sysparm_article=KB0752560
While creating a client callable script include, the general practice is to avoid overriding initialize method, which is also stated in the official documentation.
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());
If you are getting the error "No Records Selected" for list button, add sysverb to the action name.
GlideElement actually includes most of the String.prototype functions. Thus current.description.toUpperCase() for instance converts description to uppercase
Credits: János Szentpáli
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.
ServiceNow Processors are deprecated, which I never realized.
https://docs.servicenow.com/bundle/orlando-application-development/page/script/processors/concept/c_Processors.html
g_form.getGlideUIElement does not work on portal and g_form.getField does not work on normal UI. Both the functions are used to get information related to fields/variable.
For example, to get sysid of variable on catalog, you might have to do something like this.
https://gist.githubusercontent.com/iamkalai/c56b8fae9e2cae8b5bbefe132903ec88/raw/3ce2d0325e489863a02cfa7e4cd1d701bb1a44b4/Get%2520Variable%2520ID.js
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.
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');
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");
}
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
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));
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.
The state of updateset while being committed can be misleading sometimes. This is due to updates being applied using Progress workers and the state being updated via UI action.
FYI - https://hi.service-now.com/kb_view.do?sysparm_article=KB0622557
If you leave the Run As field as blank in scheduled job, ServiceNow will run the job as system user.
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);
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
Ever wish to see all the publicly available ServiceNow service portals in one place? If yes, link is in the comment section.
Credits: Nick Belli.
https://github.com/NickBelli/ServiceNowResources
Below functions can be used
Impersonate - gs.getSession().impersonate(userID);
End Impersonation - gs.getSession().onlineUnimpersonate();
You can rollback fix scripts. But note that the rollback field is not visible on form view.
Credits: Jace Benson
FYI - https://jace.pro/post/2020-04-23-fix-scripts-can-rollback-now/
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).
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
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.
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
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.
Get ServiceNow related trivia using the following webservice - "https://lnkd.in/dbZNcPN"
https://scripting.service-now.com/api/x_snc_now_trivia/trivia/getQuestion
Credits: NowLearning
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);
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.
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
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);
}
You can revert #ServiceNow workflow to any previous version Out of the box.
Credits - Chris Sanford.
gs.cacheFlush() is the equivalent of doing 'cache.do'.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.