How to execute scheduled job by fetching domain specific credentials?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2025 09:57 AM
When a scheduled job is executed, it's executed as sys_user, so it cannot fetch the domain ID of the logged-in user. The function is unable to fetch the domain-specific records from the table as the domain ID is not available.
How to get the domain ID of the current logged-in user while executing a scheduled job for a particular domain?
How to set a different scheduled frequency for each domain for the scheduled job that is bundled with scoped app global domain?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2025 01:00 PM
hi @bachhav
Get Domain ID in Scheduled Job:
Use gs.setCurrentDomainId(domainId) to set domain context manually.
Fetch domain ID from a config/custom table.
or
Use Domain Delegation or Domain Separation APIs to dynamically manage domain-specific logic and credentials.
Chandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2025 02:08 AM
Hi @SD_Chandan,
My questions are:
How to get the domain ID of the current logged-in user while executing a scheduled job for a particular domain?
How can I set a different scheduled frequency for each domain for the scheduled job that is bundled with the scoped app global domain?
The above solution is to get the Domain ID in a scheduled job. Please elaborate more on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2025 05:03 AM
1. Get Domain ID in Scheduled Job
Scheduled jobs run as the system user, not a logged-in user. To get domain-specific data:
Loop through the domain table.
Use sys_domain field in GlideRecord queries.
Optionally use GlideDomainSupport.getCurrentDomainId() if available.
2. Set Different Frequencies per Domain
You can't set multiple frequencies in one job. Instead:
Option A: Create separate scheduled jobs for each domain with different schedules.
Option B: Use one master job that runs frequently and checks per-domain last run time (stored in a custom table or property) to decide whether to execute logic.
Chandan