- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 01:19 PM
Hello Developers,
Need one help in getting approval triggered script.
I am having one requirement to trigger approval to vp level once manager approves the ritm , how to achieve this?
In user table , we are having one field called job title where vp,svp,manager,president etc are written on user profile.
Now in workflow what to be written on script , could anyone help me on this.
The flow is as below
1. end user raises a request
2. first it goes for user's manager approval .
3. after manager approval, it should trigger to directly vp level person .
here in this case, vp can be users 1st level manager, 2nd level ,3rd leve. 4th level,5th level in hierarchy.
We can get this vp level from user table field called job title.
I am getting stuck with this, could anyone please help me to achieve this with code.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 12:06 AM
you can use a workflow run script to determine the VP in that hierarchy
You can refer this link on how to handle and get the value using recursion
Recursive function returns undefined
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 11:29 PM
So the next approval is for the first 'vp' related to the requested for, no matter what level? Is that correct?
I think you need to check on the data in your system. The issue with 'job title' field is that it is a string field and even a field sometimes available for users themselves to edit (I have seen job titles like 'Head of the Hard Workers' because users were able to change it from the portal). It could be a bad call to use that field.
You also need to realize that, if there are no vp's, it will be approved automatically (default ServiceNow behavior). Wouldn't it be better to first have a user's manager approve and then a department/business unit manager? I don't know your data structure, but it would be good to start there.
If there really is no other option, your script should do a loop through the manager fields (user's manager, user's manager manager, etc) and return when the jobtitle contains 'vp'. Also make sure you have a fallback, for if no manager is filled or no vp is found. You are relying on data that is in a string field.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 12:06 AM
you can use a workflow run script to determine the VP in that hierarchy
You can refer this link on how to handle and get the value using recursion
Recursive function returns undefined
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 06:34 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader