The Now Platform® Washington DC release is live. Watch now!
09-11-2022 01:52 AM - edited 01-26-2024 09:08 PM
GlideSecurityManager.get().enableElevatedRole('security_admin');
var grActionInstance = new GlideAggregate('sys_hub_action_instance');
var strTableName = 'wm_task'; //replace with your table name
grActionInstance
.addJoinQuery('sys_variable_value', 'sys_id', 'document_key')
.addCondition('value', strTableName);
grActionInstance.addAggregate('GROUP_CONCAT_DISTINCT', 'flow');
grActionInstance.groupBy('flow');
grActionInstance.addQuery('flow.sys_class_name', 'sys_hub_flow')
grActionInstance.query();
while(grActionInstance.next()) {
gs.info(
'[{0}]\t{1}',
grActionInstance.flow.active ? 'active' : 'inactive',
grActionInstance.flow.name
);
}
var _strContextID = FlowScriptAPI.getContextID();
Your browser provides you with a complete development environment for client-side scripts in ServiceNow. Make sure you opened the page without the frameset (use /pop command from SNUtils if required), then open the Developer Tools (F12), go to "Source" -> "Snippets" and create a new one. The really cool thing is the code completion which reveals ALL methods and properties of an API like g_form. Also, code debugging with breakpoints and variable watching is possible.
There is a API GlideEmailOutbound which allows creating emails directly without utilization of notifications. After invocation of the save() method a record is created at table sys_email. But unfortunately that API does not provides a method for attaching files.
var mail = new GlideEmailOutbound();
mail.addAddress('cc', '123@123.com');
mail.addRecipient("abc@abc.com");
mail.setSubject("Test Email");
mail.save();
If you need a way to identify the name of the family release your instance is running with, you can use the following method. Another method returns the file name of the latest upgrade version:
gs.info(new sn_appclient.GlideUpgradeUtil().getCurrentBuildName()); gs.info(new sn_appclient.GlideUpgradeUtil().getCurrentBuild());
There is an undocumented API which can convert the value from GlideDateTime object into a human readable format, like "3 months from now" or "2 weeks ago":
gs.info(new GlideTimeAgo().format(new GlideDateTime('2023-01-08 07:13:22'));
var objPhoneNumber = new GlideElementPhoneNumber();
var isValidPhoneNumber = objPhoneNumber.setPhoneNumber( '+49 170 123456789', true);
gs.info(isValidPhoneNumber);
gs.info(objPhoneNumber.getTerritory());
now.sow.*
now.sow.home
<FIELD> is not empty AND <FIELD.SysID> is empty
GlideEmailWatermark().parseMessageNumber(<EMAIL BODY TEXT>);
If you want to debug your ACLs and only see ACL log statements which are related to refusing access to user, you can invoke from "Scripts - Background":
GlideSessionDebug.enable("security_refuse");
The same you can do if you want to see only ACL log statements which are related to granting access to user:
GlideSessionDebug.enable("security_grant");
if transactions are running in background, you can print ACL logs to node log file by:
GlideSessionDebug.enable("security_refuse, true");
GlideSessionDebug.enable("security_grant, true");
GlideTransaction.get().getRequest().getRequestURL()
GlideServlet.getSystemID();
GlideTransaction.get().getRemoteAddr()
new GlideRecord('incident').isValid();
gs.tableExists("incident");
A simple and undocumented timezone converter in server-side scripts:
var strConvertedDateTime =
new GlideScheduleDateTime("2022-03-03 06:30:00").convertTimeZone("CET", "IST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime);
gs.info(gdtConvertedDateTime);
new GlideRecord('incident').isValidField('number')
getValue();
new ScriptIncludeName().getValue();
GlideSessions.lockOutSessionsInAllNodes('<USER NAME>')
current.update();
You would like to know how much space the database in your ServiceNow instance has? Enter the following command in the Scripts console:
gs.info(
SNC.UsageAnalyticsScriptUtils.getCount(
'Primary DB size (MB)',
'Primary DB size of this instance (in MB)'
)
);
In the Community users often ask how to remove the tags from HTML content. And that's the (undocumented) answer:
new GlideSPScriptable().stripHTML(yourHtmlStr);
This is a fantastic list of tips and tricks. I have bookmarked it for future use. Thank you.
By the way, there's no need to use the &sysparm_group_sort parameter anymore in Tokyo. This functionality has been added to the list view:
The arrow icon will show up once you group by any of the visible headers.
thanks for the tip and I already have provided it on LinkedIn (https://www.linkedin.com/posts/maik-skoddow_servicenow-activity-6982302867248275456-fIwb?utm_source=... )
The problem with the new community is the limitation of 60000 characters for an article and thus I cannot extend it anymore.
If that limitation is not is increased, I have to create another article 😞
That's actually where I saw it first, and commented on it! It just didn't register that you were the same person.
Fantastic list, really appreciate the time to put this together!
Helpful content.
Fantastic list, yes !!
Bookmarked
Appreciate the updates, this is so helpful!
Fantastic! I have also bookmarked this and shared it with my DEV team Kudos to you sir!!
super welldone , i love this
very impressive. I have favorited this!
As for the question, I'm having trouble running the script below.
gs.info(
SNC.UsageAnalyticsScriptUtils.getCount(
'Primary DB size (MB)',
'Primary DB size of this instance (in MB)'
)
);
Output is "*** Script: 0"
I'm looking for a code that defines "SNC.UsageAnalyticsScriptUtils.getCount" to find the cause, but I can't find it.
Where is the script where this code is defined?
Also, any ideas what might be causing this output result?
Nice Article 🙂 I, Really Impressed by the way it was presented.
"Fun fact: The Sys ID of the "Default view" record at ServiceNow table sys_ui_view is not the well-known 32-characters long text but "Default view"
... more fun: There are actually ~800 sys IDs in the system which are not 32 hex chars - 700 or so in the "Design System Icons" table, Many of the other 100 are in constant use; tables ACL Operations and Types, Numbers etc. Some have been in the system pre-Aspen, others recently.
The CI Relationship Types table did have the sys IDs of "1" and "2" but they were silently updated to 32 hex around Geneva from memory. They were survivors from the first release of pre-ServiceNow GlideSoft. They were the foundation records - to record an incident against a CI you need a CMDB. CIs related together by type created a CMDB.
Thank you, for this fantastic list !
Amazing.
Thank you for taking the time to put this together.
The link for tile "Next Experience UI | Global Text Search" is faulty: it contains the HTML entity instead of the ampersand (& vs. &).
Fantastic! I have bookmarked this.
Kudos to you sir!!
Great list - I have bookmarked it as well.
Thank you!
@Maik Skoddow - Wonderful collection of information. Thank you for sharing!
I have a question related to the 'Subscription & License Management | Roles' section. I know the leading practice is to let users inherit their roles from the groups they are member of instead of direct roles assignments. However, knowledge base owners and managers are automatically assigned a knowledge role directly by the system (ServiceNow). When I implemented the ' Prevent direct assignment of licensable roles to users', it interfered with the role assignment during the creation of a new knowledge bases. Did you encounter this problem? If yes, how did you work around it?
Closely related question - I attempted to create scripts that will automatically add/remove the KB owners and managers to/from a group so I could associate a subscription to the group to account for the subscription allocations. I was able to get the script working that adds users to the group when a knowledge base is created or updated, but I am struggling with the script to remove the users from the group when they are no longer a KB owner or manager.
If anyone sees the problem, please let me know how to fix it. Many thanks!
Business rule - Remove owner from LIC group
Table - kb_knowledge_base
When - after Insert & Update
Filter condition - Owner changes
(function executeRule(current, previous /*null when async*/ ) {
var ownUsrid = previous.owner.user_name;
var memGr = new GlideRecord('sys_user_grmember');
memGr.initialize();
memGr.addQuery('group', 'ca791aabdb17201036d8af6d139619e4'); // the sys_id of the LIC_USR_SET-Knowledge group
memGr.addQuery('user', previous.owner);
memGr.query();
if (memGr.next()) {
memGr.deleteRecord();
}
//gs.info('Removing '+previous.owner+ 'from LIC_USR_SET-Knowledge group sys_id ca791aabdb17201036d8af6d139619e4');
})(current, previous);
Hi,
this link doesnt work. Is this on how to add documentation link to help pages within servicenow for licensed users?
Thank you for the hint! It seems that the linked artcle wasn't migrated from the old community portal to the new one last year and thus is now lost. But I added a respectice tip at the top so I don't need to rewrite it.
Thank your for sharing your list. I hope more will share within this community (like this) in making this community more interactive with each other. I've met so many knowledgeable people, who actually care about providing the best functions and support for their customers. Thanks again! Bookmarked!