The CreatorCon Call for Content is officially open! Get started here.

sarah_bioni
ServiceNow Employee
ServiceNow Employee

When users log in to Now Mobile or Agent Mobile, you may want to display a pop-up message based on specific conditions, such as user roles or particular data. However, there's a caveat: declarative conditions won't work during login because the user isn't yet in a specific context.

 

⚠️ Why Declarative Conditions Fail

During login, the context type defaults to "global" since the user hasn't accessed any record yet. Declarative conditions in event actions rely on evaluating a record in context. Without a record, the condition always returns "true", causing the pop-up to appear regardless of your logic.


Solution: Use Scripted Conditions

To implement meaningful logic, you must use a scripted condition. This allows you to run a script include or server-side logic that can query records, check user attributes, or apply custom rules.

 

🔍 Example Script

function run() {

return false; // or true based on your logic

}

run();

 

This simple script controls whether the pop-up appears. You can expand it to include more complex logic, such as:

 

JavaScript

function run() {

var user = gs.getUser();

var roleCheck = user.hasRole('admin');

return roleCheck;

}

run();


⚠️ Performance Considerations

Be cautious when implementing the logic. Since this script runs during login, avoid heavy queries or complex loops that could impact performance. Always test under load if you're deploying to production environments.


🧠 Pro Tip

Use a Script Include if your logic is reusable or involves querying multiple tables. This keeps your condition clean and maintainable.


Summary

  • Declarative conditions don’t work during login due to a lack of context.
  • Use scripted conditions to control pop-up visibility.
  • ⚠️ Keep logic lightweight to avoid performance issues.

Version history
Last update:
‎09-01-2025 07:12 AM
Updated by:
Contributors