- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 11:10 PM
I am calling script include from UI action what will happen if i doesn't pass current object?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 11:40 PM
Hi Nick,
it's not necessary to pass the current object since it is the same calling scope.
But it is recommended to pass the current object from the UI action to the script include function considering how objects are treated in javascript.
Refer below link for more explanation
https://snprotips.com/blog/2019/12/18/can-script-includes-use-the-current-variable
Just tested for Form button and it worked well without sending the current object in script include function and was able to print the incident number
Screenshots below
UI Action:
Script Include:
Output: Printing the current inc number
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 11:13 PM
Hello Nick,
You need to pass current object if you need to access the field values in the script include. Sample script below on how to pass current object.
For ex : var val = new HelloWorld();
val.test(current);
Now at script include end
test: function(gr)
{
var shortDesc = gr.short_description;
}
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 01:10 AM
Understood
Thanks Pradeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 11:16 PM
Hello,
You can add current object in Ui actions.
Script include Name:Hello
Script:
function Hello(){
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();
}
If answer is helpful please mark correct!
Thanks,
Pratiksha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 11:40 PM
Hi Nick,
it's not necessary to pass the current object since it is the same calling scope.
But it is recommended to pass the current object from the UI action to the script include function considering how objects are treated in javascript.
Refer below link for more explanation
https://snprotips.com/blog/2019/12/18/can-script-includes-use-the-current-variable
Just tested for Form button and it worked well without sending the current object in script include function and was able to print the incident number
Screenshots below
UI Action:
Script Include:
Output: Printing the current inc number
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader