Create a new Scheduled Job, making sure that it is in the VividCharts Application Scope.
Paste the following script listed below into the script portion of the Scheduled Job.
Script:
/*
Refreshes the reports identified in the x_vivid_vc_core.scheduled_refresh_reports sys_property.
Intended for use in a scheduled job.
*/
// Config variables
var reports = gs.getProperty("x_vivid_vc_core.scheduled_refresh_reports") || null; // The report to be refreshed
var userDisplay = "System"; // The name that will appear under refresh info
if (reports) {
// Refresh portals.
var portalsGR = new GlideRecord("x_vivid_vc_core_view_portal_connection");
portalsGR.addQuery("view", "IN", reports);
portalsGR.query();
while (portalsGR.next()) {
var viewSysID = portalsGR.getValue("view");
var portalSysID = portalsGR.getValue("portal");
refreshPortal(viewSysID, portalSysID, userDisplay);
}
// Refresh slide decks.
var slideDeckGR = new GlideRecord("x_vivid_vc_core_view_slides_connection");
slideDeckGR.addQuery("view", "IN", reports);
slideDeckGR.addQuery("view.type", "!=", "summary");
slideDeckGR.query();
while (slideDeckGR.next()) {
var viewSysID = slideDeckGR.getValue("view");
var publishedSlideDeckSysID = slideDeckGR.slides.published.toString();
if (publishedSlideDeckSysID) {
refreshSlideDeck(viewSysID, publishedSlideDeckSysID, userDisplay);
}
}
}
function refreshPortal(viewSysID, portalSysID, userDisplay) {
try {
// define a job ID for collection history
var jobID = CollectionHistory.generateJobID();
// create the factory
var factory = new PortalFactory();
// create the portal
var portal = factory.createPortal(portalSysID);
var portalView = portal.getPortal().view;
// mark these views as refreshing before the job gets picked up
CollectionHistory.startSummaryCollection({
setID: null,
cardDeck: portal.cardDeck,
userDisplay: userDisplay,
jobID: jobID,
portalFilter: null,
});
// create the event options
var eventOptions = {
portalID: portalSysID,
viewID: portalView,
set: null,
userDisplay: userDisplay,
jobID: jobID,
portalFilter: null,
};
var eventOptionsString = JSON.stringify(eventOptions);
// add a collection task to the queue
var nonUsedQuery = new GlideRecord("x_vivid_vc_core_portal");
nonUsedQuery.addQuery('sys_id', portalSysID);
nonUsedQuery.query();
if (nonUsedQuery.next()) {
gs.eventQueue('x_vivid_vc_core.collect_summary', nonUsedQuery, eventOptionsString);
}
} catch (err) {
// handle error
VividFunction.processError(err);
}
}
function refreshSlideDeck(viewSysID, publishedSlideDeck, userDisplay) {
try {
var historyID = CollectionHistory.startCollection({
user: userDisplay,
userDisplay: userDisplay,
view: viewSysID,
});
// create an event
var asyncInputs = {
sys_id: publishedSlideDeck,
target: null,
userDisplay: userDisplay,
historyID: historyID
};
// add a collection task to the queue
var queueQuery = new GlideRecord("x_vivid_vc_core_queue_results");
queueQuery.finished = false;
queryID = queueQuery.insert();
var queryInputs = JSON.stringify(asyncInputs);
gs.eventQueue('x_vivid_vc_core.refresh_view', queueQuery, queryInputs);
} catch (err) {
VividFunction.processError(err);
}
}
Next, create the x_vivid_vc_core.scheduled_refresh_reports sys property. You can locate the correct View sys_id from the x_vivid_vc_core_views table. Search for the view by title and copy the View sys_id.
Paste the copied View sys_id into the value of the new sys_property. You can also use a comma separated list to refresh more than one view like this: e4badfb61b896250a3c20dc5604bcb52,63cbb0f61bcd2250a3c20dc5604bcbd0
You can create a new Scheduled Job and sys property for each view that you would like to refresh more than once daily.
β
β