
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2015 06:39 AM
Can we use "Current" object in Script Include? Please be specific. Yes or No.
If 'Yes', then how? Shouldn't we need to pass the "Current" object to the function or instantiate a GlideRecord object in the script include function?
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2015 09:48 PM
Indeed. Here goes an example using a classless Script Include:
Script include Name: sayHello
Script:
function sayHello(){
gs.addInfoMessage(current.number);
}
I can then call that script include from an incident onBefore insert/update Business Rule with the script:
function onBefore(current, previous) {
sayHello();
}
And upon an insert or update of an incident it will display the incident number as an Info Message in the screen.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2015 05:20 AM
You mean it will work only for client callable script include? Or else it will not wrok?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2015 05:59 AM
Yes. If you follow Berny's example above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2015 10:02 PM
Hi swarnadeepnandy,
Do you have any further questions or can we close this thread by marking the responses as helpful/correct?
Thanks,
Berny

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2016 12:59 AM
Another Use Case - If your UI Action conditions are hard to read, you can put them in Script Includes instead.
Make sure your naming convention makes it clear that the function is in the context of a particular record type.
Example
Script Include: IncidentContext
var IncidentContext= Class.create();
IncidentContext.IsResolvedAndFPOC = function() {
return (
current.state == 10
&& current.u_fpoc == true
&& current.u_long_custom_field == 'meaningless string'
);
}
UI Action Condition
IncidentContext.IsResolvedAndFPOC();
Much easier to read!
You can now immediately understand what your condition is looking for.
Don't fall into the trap of naming is something like IsUIActionBlaVisible - because that tells you nothing about what your code is actually checking for.
Hope this helps.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 03:27 AM
Hi Swarnadeep,
Yes, You can use the current object in script include provided you pass it through initialize() function and in the initialize() function
have this this.currentObj = current;
This variable this.currentObj can then be used throughout the script include functions.
Mark my reply as Correct and also hit Like and Helpful if you find my response worthy.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader