Triggering executing a scheduled job when configuring an app
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2016 06:29 PM
Hi Community!
My team is developing a custom application which has a small number of external API calls - both PUT and GET messages which we use to syncronise data with an external system.
We currently ask our customers to enter their API key (and some other config data) into a Property page, and we have scheduled job records which will regularly perform synchronisation activities to send and receive data during the course of the application, but I would like a function where the customer can manually trigger the Scheduled Job.
Is there a nice, user friendly way for me to put a UI Action or button on a property page which can be used to trigger a scheduled job or will I be stuck putting instructions in my installation guide telling my users to navigate to scheduled jobs, find the job and then execute it manually? Looking for user friendly solutions preferably.
Cheers,
Kevin Clark
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2016 07:44 AM
Hi Kevin,
The below should help you out, it details how to execute a scheduled job via a script. If you add the button to the page and just have the onClick function run using code you've wrote based on this example - that should do it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2016 02:56 PM
Hi Michael,
Yep I know I can add a button to a normal form or record that will trigger a script, and I can make that script execute the Scheduled Job. What I'm looking for is a logical User Experience for the users.
At the moment our User Journey upon installing the app is this:
1. Install App from ServiceNow Store
2. Ensure external service is running and API key has been retrieved
3. Configure SN app parameters including API Key credentials on a Property page
4. ***Trigger initial data synchronisation between SN and external service via Scheduled Job***
5. Commence using Service
As per the best practice for ServiceNow Apps, the vast majority of our configuration is done in the Property page, however as far as I can tell, we don't have the ability to add a UI action or explicitly call a script when the user saves their property page - there's no way to essentially "turn on" the app once the configuration has been completed.
At the moment I have the Scheduled Job record directly linked as a Menu Item in the app, andmy Install guide says "go to the Scheduled Job from the menu and click 'Execute Now'", but I'd rather the customer didn't have to look at our code or system-related records and just had a fancy button to click from the property page that they have just finished configuring.
We *could* try to create a separate UI Page or form or something where the customer could manually execute the "first run" of the scheduled job rather than wait overnight.
I consider the behaviour we have at the moment - going to the scheduled Job and clicking execute now to be a poor user experience, and would like to have buttons available in property pages, but that may not be possible.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2016 06:03 PM
Hi Kevin,
Is there a reason you still must run the manual sync as a scheduled job? Why not include the same functionality in a utilitarian script include that you can just call as part of your action when saving the application properties? You should be able to accomplish the same tasks without scheduling it to run and then triggering it manually.
Thanks,
-Brian
Edit: As a side note, you can look at the code for their "Execute Now" UI Action and replicated it. They basically just save any updates to the scheduled job record and then launch it:
current.update();
SncTriggerSynchronizer.executeNow(current);
I don't know of any reason you couldn't use a GlideRecord to get your scheduled job record in table [sysauto] and use the same SNC command to execute it, all from within your own UI Action/utility/script include that you call once the properties are saved. But I don't see why you would have to do this over just calling your functionality directly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2016 06:50 PM
Hi Brian,
No, there's no reason why we couldn't have a separate standalone function tied to the Save button in the Properties page. That's totally valid, however, I'm not sure if we get the ability to modify buttons on Properties pages as part of a scoped app... you certainly don't seem to be able view that UI action directly from within the property page.
You have raised an interesting possibility though - Maybe I could set up a business rule that watches for updates to certain records within sys_properties? Maybe I have that BR watch for a change to the API Key property which triggers a script when it changes?
I'll explore that as an option.
Kevin