
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 06-20-2021 01:37 AM
How to make Notification/Email Links dynamic when accessing via Desktop & Mobile
This Article provides you an idea on how you can make a link that acts dynamically based on the Device Type that you are accessing the link.
Use Case:
- I want to send a notification/email to the Fulfiller when the Requestor submits a catalog item request.
- I want to provide a link within that Email to direct him to take to the RITM to see what Requestor submitted
- If the Fulfiller opens the email using his Mobile, the RITM should opens using the Servicenow Agent Mobile App & if the Fulfiller opens the email using desktop, it should redirect him to the resolver view.
Servicenow API: MobileDeepLinkGenerator
There is an OOTB API called MobileDeepLinkGenerator where you can utilize this to construct the URL dynamically.
Reference: Click here
Step by Step Configuration
- Create a Portal Page and name it as “devicetype”
- Create a Script Include called “LinktoOpen” and add the below code
-
var LinktoOpen = Class.create(); LinktoOpen.prototype = Object.extendsObject(AbstractAjaxProcessor, { getLink: function() { var mb = this.getParameter('sysparm_mobile'); var tbl = this.getParameter('sysparm_tbl'); var sysid = this.getParameter('sysparm_sysid'); var link = 'sc_req_item.do?sys_id=' + sysid; if(mb) { var deepLinkGenerator = new global.MobileDeepLinkGenerator("agent"); link = deepLinkGenerator.getScreenLink("119ed9cf2f2460102dab2aa62799b6dd"); //SYS_ID OF YOUR APPLET } return link; }, type: 'LinktoOpen' });
- Create a Widget called “dtype” and add the below code
-
Server Script (function() { /* populate the 'data' object */ /* e.g., data.table = $sp.getValue('table'); */ data.tbl = $sp.getParameter('tbl'); data.sysid = $sp.getParameter('sysid'); })(); Client Controller function me($scope, $window) { var c = this; var isMobile = window.orientation > -1; var ga = new GlideAjax('LinktoOpen'); ga.addParam('sysparm_name','getLink'); ga.addParam('sysparm_mobile',isMobile); ga.addParam('sysparm_tbl',c.data.tbl); ga.addParam('sysparm_sysid',c.data.sysid); ga.getXML(getlnk); function getlnk(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); $window.location.href = answer; } }
- Create a Notification Script and name it as “mobile_deeplink”
-
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template, /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, /* Optional GlideRecord */ event) { var link = 'https://dev23541.service-now.com/sp?id=devicetype&tbl=sc_req_item&sysid=' + current.getValue('sys_id'); try { var hr = '<a href="' + link + '"' + ' target="_blank">Go to the RITM</a>'; template.print(hr); } catch (e) { } })(current, template, email, email_action, event);
- Create a Notification and configure
-
- “When to send” to On insert of RITM
- Recipients as the Resolver (You may include a default Resolver within the workflow of your catalog item just to see whether he is getting the email)
- Also, make sure you configure Email properties to send the email & have the email field on sys_user filled with a proper email.
Notification “What it will contain” Tab can be like this
Message HTML
Number: ${number}
Click below to open the Ticket. It opens with your NOW Mobile App when you are using your Mobile & Opens the SP Portal Status page when you are in Desktop.
${mail_script:mobile_deeplink}
Now, Submit a request and see what happens on both Desktop & Mobile when you receive the email
Mobile View
Desktop View
When you click from desktop, it opens like this
When you click from Mobile, it opens like this
Please bookmark & mark it as helpful. Let me know in case of any further information required.
Thanks,
Narsing
- 4,455 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello. I have a couple of questions.
- Where you say "Create a Portal Page" is that in the "Pages" table (under Service Portal menu), i.e., the sp_page table?
- Can you help me with finding the Applet sys_id for the Script Include, or point me in a direction to help me figure this out?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
Applets can be found from System Mobile ==> Applets Table
Portal page can be created via Service Portal ==> Pages
Thanks,
Narsing
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
On my fresh PDI the module is System Mobile > Screens (sys_sg_screen
table)
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Narsing,
The steps you provided to set up dynamic deep links for an email keep directing me to Okta to sign on.
Do you know of any additional steps that can be taken to avoid authenticating in OKTA?
Thanking you in advance.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey,
Can you make the page/Widget as "Public" and see whether it works
Thanks,
Narsing

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
We have a similar requirement and I performed the steps exactly as you mentioned. It is opening the link in mobile but with all the details are blank. Checked with ServiceNow but as its a customization, didn't get any support.
Could you please check once and help.
Thanks.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
Have you configured your Agent Mobile App with your Instance?
Have you tried with your PDI and is working?
If it is working with the PDI and not with your Company Instance, then it could be some security restriction that needs to be worked with them
Can you check the Mobile Deep link with your Applet in the background script and see whether you are really getting the response.
var deepLinkGenerator = new global.MobileDeepLinkGenerator("agent");
link = deepLinkGenerator.getScreenLink("119ed9cf2f2460102dab2aa62799b6dd");
gs.print(link);
Thanks,
Narsing

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Narsing,
I created another link using "MobileDeepLinkGenerator" and that is working fine. But, this one is bringing blank fields in mobile. I ran this code and this created the link but that seems to be different than that of the one which gets generated with function "getformscreenlink".
Don't think there would be any restriction from instance as other links are working.
Thanks,
Nitu
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello:
Any success with this? I am adding 2 links in the email script, one for browser and one for mobile.
I have modified the below line in mobile_deeplink notification script
var link = 'https://dev23541.service-now.com/sp?id=devicetype&tbl=sc_req_item&sysid=' + current.getValue('sys_id');
to
var link = 'https://dev23541.service-now.com/nav_to.do?uri=sc_req_item?sysid=' + current.getValue('sys_id');
And I am not even creating the widget. Just want to see the RITM in browser...instead of portal. But this only displays a new RITM record.
For mobile App, I have added the following
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I have figured out how to make it work with 2 separate links from the email. Corrections to my above post if anyone is interested:
For browser (not portal)
var link = 'https://<instance name>/nav_to.do?uri=sc_req_item%3Fsysid%3D' + current.getValue('sys_id');
For mobile App, I have added the following
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
What's the purpose of creating the portal page and widget? Need to understand why.