How to change Target URL in Change Interceptor based on logged in user's mail id dynamically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2025 10:00 AM
Hello Everyone,
Is there an option to change the target URL dynamically in Change Interceptor (sys_wizard_answer table), based on logged in user mail id.
For example:
I have created two templates -> testuser_template, exampleuser_template
If the user mail id contains @test.com, then the URL should map to testuser_template in sysparam_template -> query string
If the user mail id contains @Example.com, then the URL should map to exampleuser_template in sysparam_template ->query string
The target URL in the below should get changed dynamically based on the above conditions.
Regards,
Akila
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2025 12:46 AM
Hello @Akila Ravichand,
- Create a Script Include:
- Navigate to System Definition > Script Includes.
- Create a new script include (e.g.,
ChangeInterceptorHelper
). - Set Accessible from to "All" or a specific scope if needed.
- Set Client callable to "false" (unless you need client-side access).
- Add the following script (replace with your specific logic for determining the URL based on email):
var ChangeInterceptorHelper = {
getDynamicTargetUrl: function() {
var userEmail = gs.getUser().getEmail();
var targetUrl = '';
// Example logic:
if (userEmail.endsWith('@example.com')) {
targetUrl = 'https://instance.service-now.com/nav_to.do?uri=%2F$m2m_change_request_form.do%3Fsysparm_stack=no%26sysparm_view=ess';
} else if (userEmail.endsWith('@example.net')) {
targetUrl = 'https://instance.service-now.com/nav_to.do?uri=%2F$m2m_change_request_form.do%3Fsysparm_stack=no%26sysparm_view=itil';
} else {
targetUrl = 'https://instance.service-now.com/nav_to.do?uri=%2F$m2m_change_request_form.do%3Fsysparm_stack=no'; // Default URL
}
return targetUrl;
}
};
- Modify the Interceptor:
- Navigate to System Definition > Interceptor.
- Open the Change Request interceptor you're using.
- Go to the "Answers" related list.
- Open the relevant answer record.
- In the "Target URL" field, replace the existing URL with:
- Navigate to System Definition > Interceptor.
javascript:new ChangeInterceptorHelper().getDynamicTargetUrl()
ChangeInterceptorHelper
with the name of your script include.
- Test the Solution:
- Log in with different user accounts (with different email domains, if applicable).
- Trigger the interceptor (e.g., by clicking a "Create Change" button).
- Verify that the Target URL is correctly set based on the user's email.
If this is helpful, please hit the thumbs up button and accept the correct solution by referring to this solution in future it will be helpful to them.
Thanks & Regards,
Abbas Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2025 04:11 AM
Hello @Abbas_5 ,
Thanks for your response. I have tried it and unfortunately, it is not working as expected.
The script includes returns the URL based on user email. But when the same is used in the Target URL, it is not redirecting to any page and stays in the interceptor page itself.
I also trying using the script include in Script field and removed the details from Target URL. Still it was same.(in this scenario, it redirects to a blank page).
(I tried using your sample code too, for the different URLs, and the result was still the same).
Regards,
Akila