Cannot use gs.IsMobile()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi everyone,
I hope you're doing well.
I need help regarding how to identify is a HR Case is created via mobile. Basically what I want to achieve is when an HR Case is created via mobile, It would change the source to 'Mobile app'.
I was using a business rule where the condition was gs.IsMobile(), but I was with the property 'glide.ui.m_enabled' as 'true' and I need tot keep it as 'false' and I also cannot change the property 'glide.ui.mobile_agents'.
Anyone has any ideia how to workaround this?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hello @rafas_10
Problem: gs.isMobile() returns false when glide.ui.m_enabled=false, so you can’t rely on it to detect mobile origin.
-------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
Also Please check below solution this should work
https://www.servicenow.com/community/developer-forum/i-can-t-use-gs-ismobile/m-p/2654317
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0785111
If my response helped mark as helpful and accept the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @kalanidhikr , @AnkaRaoB ,
The proposed solution returns userAgent as null, therefore it's not recognizing when I'm using mobile app. This means it will not be achievable?
Regards.
Sérgio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
HI @rafas_10 ,
method gs.isMobile() only works when the property glide.ui.m_enabled = true.
If this property is disabled (and cannot be changed), gs.isMobile() will always return false.
So, it cannot be used to detect cases created from the ServiceNow Mobile App in this scenario.
Recommended Workaround (Best Practice)
When a record is created from the Mobile App, the request contains a special User-Agent value such as:
ServiceNowMobile
NowMobile
ServiceNow Mobile
You can detect this using a Before Insert Business Rule.
Sample Business Rule
Table: sn_hr_core_case
When: Before Insert
(function executeRule(current, previous) {
var userAgent = gs.getSession().getClientData('user_agent') + '';
if (userAgent.toLowerCase().includes('servicenowmobile') ||
userAgent.toLowerCase().includes('nowmobile') ||
userAgent.toLowerCase().includes('servicenow mobile')) {
current.source = 'Mobile app';
}
})();
If this helps you then mark it as helpful and accept it as solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
I doubt this is feasible to achieve
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
