Name

global.PublicationUtils

Description

No description available

Script

var PublicationUtils = Class.create();
PublicationUtils.prototype = {
  initialize: function() {
  },

  createEmailNotification: function(name,collection,generation_type,action_update,condition,template){
  	//Make sure we have at least one user in CC
  	var smtp_address = "";
  	var category = "4a789ea27f3032005f58108c3ffa91af";
  	var gr = new GlideRecord('sys_email_account');
  	gr.addActiveQuery();
  	gr.addQuery('type','smtp');
  	gr.query(); 
  	if (gr.next())
  		smtp_address = gr.getValue('from') ? gr.getValue('from') : gr.getValue('user_name');

  	var gr_notif = new GlideRecord('sysevent_email_action');
  	gr_notif.initialize();
  	gr_notif.setValue('name',name);
  	gr_notif.setValue('collection',collection);
  	gr_notif.setValue('generation_type',generation_type);		
  	gr_notif.setValue('action_update',action_update);
  	gr_notif.setValue('condition',condition);
  	gr_notif.setValue('recipient_users',smtp_address);
  	gr_notif.setValue('template',template);
  	gr_notif.setValue('category',category);
  	var notificationId = gr_notif.insert();
  	return notificationId;
  },

  deleteEmailNotification: function(notificationId){
  	var gr = new GlideRecord('sysevent_email_action');
  	if(gr.get(notificationId)){
  		gr.deleteRecord();
  	}
  },

  updateEmailNotification: function(notificationId,template){
  	var gr_notif = new GlideRecord('sysevent_email_action');
  	if(gr_notif.get(notificationId)){
  		if(template){
  			gr_notif.setValue('template',template);
  			gr_notif.update();
  		}
  	}
  },

  checkPublicationPassPublishDate: function(publicationId){
  	var gr = new GlideRecord('sn_publications_publication');
  	if(gr.get(publicationId)){
  		var start = (new GlideDateTime(gr.getValue('publish_date'))).getNumericValue();
  		var now = new GlideDateTime().getNumericValue();

  		if (now >= start){
  			return true;
  		}else
  			return false;

  	}else
  		return false;
  },

  getChoiceList: function(table,element){
  	return GlideScriptChoiceList.getChoiceList(table,element);
  },

  generateURL: function(table,sysId){
  	return gs.generateURL(table,sysId);	
  },

  scopedGlideRunScriptJob: function(script){
  	return GlideRunScriptJob.scheduleScript(script);
  },
  type: 'PublicationUtils'
};

Sys ID

32965a34c30112004bd67bfaa2d3aefe

Offical Documentation

Official Docs: