- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 11:54 PM
Hello
When I write scripts (business rules, script includes (classes and functions), functions) I try to add the name to the log output.
like:
function add_sec_sc_relation_function()
{ gs.log('add_sec_sc_relation_function ' + 'start');
}
Then I can filter to the syslog table with this string. (Best way to debug).
Is there a way to get the function name without hard coding ? like
gs.log(get_name_of_function() + ' start');
Many thanks.
Sincerely Detlef Biedermann
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 12:02 AM
Hi,
you cannot get the current function name
best way is to print logs at start of the function and end of function to ensure the script within function ran fine
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
10-08-2020 12:02 AM
Hi,
you cannot get the current function name
best way is to print logs at start of the function and end of function to ensure the script within function ran fine
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
10-08-2020 01:04 AM
Hi,
you can use arguments object and can fetch the name by using some string manipulations.
Check this link https://www.geeksforgeeks.org/how-to-get-currently-running-function-name-using-javascript/ This might give you some ideas.
Mark the comment as a correct answer and helpful if this helps to solve the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 01:19 AM
Hello
I have tried in "Script Background"
function getFuncName()
{
return getFuncName.caller.name;
}
function teddy() {
gs.info(getFuncName());
}
teddy();
Result:
*** Script: undefined
Sincerely Detlef Biedermann

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 01:25 AM
Did you try arguments.callee.toString()
This returns the source. Check the below link. This might give you some ideas