- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 07:20 AM
Trying to call a same function until the value is found. But when the value is found its returning undefined.
var user=new GlideRecord("sys_user");
user.get("1328d77f97ea45104c913b6e6253af14");
checkmanageradbusinessunit(user.u_business_unit,user.manager)
function checkadbusinessunit(businessunit, manager)
{
if(businessunit == "")
{
gs.print(checkmanagerbusinessunit(manager));
}
}
function checkmanagerbusinessunit(manager) {
gs.print("check manager")
var user = new GlideRecord("sys_user");
user.get(manager);
if(user.u_business_unit == "")
{
gs.print("if");
checkmanagerbusinessunit(user.manager);
}
else{
var bu=user.u_business_unit;
gs.print(bu);
return bu;
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 08:07 AM
Hi caffry,
declare the recursive function in a temp variable and check.
var user=new GlideRecord("sys_user");
user.get("1328d77f97ea45104c913b6e6253af14");
checkmanageradbusinessunit(user.u_business_unit,user.manager)
function checkadbusinessunit(businessunit, manager)
{
if(businessunit == "")
{
gs.print(checkmanagerbusinessunit(manager));
}
}
function checkmanagerbusinessunit(manager) {
gs.print("check manager")
var user = new GlideRecord("sys_user");
user.get(manager);
if(user.u_business_unit == "")
{
gs.print("if");
var temp;
temp=checkmanagerbusinessunit(user.manager);
}
else{
var bu=user.u_business_unit;
gs.print(bu);
return bu;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 07:30 AM
check this link for recursive function solution
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
‎04-18-2022 07:53 AM
Hi Ankur,
I dont see much differences on the script.
its similar to the one which i wrote but still something is failing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 07:33 AM
Can you try changing the last 2 lines to
var bu= user.u_business_unit.toString();
return bu.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 07:48 AM
Still it didnt work