Name
sn_cd.cd_ScheduledContentListDeleteAjax
Description
Given a list of scheduled content sys ids, remove any records with parents already in the list, since these records would get deleted automatically
Script
var cd_ScheduledContentListDeleteAjax = Class.create();
cd_ScheduledContentListDeleteAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
/**
* @ajaxparam {Array} sysparm_ids - the ids of the sn_cd_content_visibility records
* @return {Array} - the ids of the sn_cd_content_visibility records minus the child records with parents already in the list
**/
removeRedundantChildRecords: function() {
var contentIds = JSON.parse(this.getParameter('sysparm_ids'));
if (!contentIds || contentIds.length == 0)
return false;
// Find record parents if they exist
var scheduleContentGr = new GlideRecord('sn_cd_content_visibility');
scheduleContentGr.addQuery('todo_scheduled_content', 'IN', contentIds);
scheduleContentGr.query();
// If parent is in delete list, skip child
var contentIdLookup = {};
for (var contentIdx = 0; contentIdx < contentIds.length; contentIdx++)
contentIdLookup[contentIds[contentIdx]] = null;
while(scheduleContentGr.next())
if (contentIdLookup.hasOwnProperty(scheduleContentGr.getUniqueValue()))
delete contentIdLookup[scheduleContentGr.todo_scheduled_content.toString()];
return JSON.stringify(Object.keys(contentIdLookup));
},
type: 'cd_ScheduledContentListDeleteAjax'
});
Sys ID
226e1569733220107eb79dece03b15f9