Last active
October 13, 2021 09:27
-
-
Save beckettkev/6f3389963294aa1b566a59fde48dc245 to your computer and use it in GitHub Desktop.
JavaScript for Adding a Document Library Email Alert for the loggged in User
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ctx = SP.ClientContext.get_current(); | |
this.user = ctx.get_web().get_currentUser(); | |
this.alerts = this.user.get_alerts(); | |
this.list = ctx.get_web().get_lists().getByTitle('Documents'); | |
ctx.load(this.user); | |
ctx.load(this.alerts); | |
ctx.load(this.list); | |
ctx.executeQueryAsync(()=> { | |
let alertTime = new Date(); | |
alertTime.setHours(alertTime.getHours() + 24); | |
let notify = new SP.AlertCreationInformation; | |
notify.set_title('Documents - Movers and Shakers'); | |
notify.set_alertFrequency(SP.AlertFrequency.daily); | |
notify.set_alertType(SP.AlertType.list); | |
notify.set_list(this.list); | |
notify.set_deliveryChannels(SP.AlertDeliveryChannel.email); | |
notify.set_alwaysNotify(true); | |
notify.set_status(SP.AlertStatus.on); | |
notify.set_alertTime(alertTime); | |
//notify.set_user(this.user.get_loginName()); | |
notify.set_user(this.user); | |
notify.set_eventType(SP.AlertEventType.all); | |
// 0 = Anything Changes | |
// 1 = Someone else changes a document | |
// 2 = Someone else changes a document created by me | |
// 3 = Someone else changes a document modified by me | |
notify.Filter = '0'; | |
debugger; | |
this.alerts.add(notify); | |
this.user.update(); | |
ctx.executeQueryAsync(()=> { console.log('CHEESE ON TOAST!'); debugger; }, ()=> { console.log('EGGS!'); }) | |
}, ()=> { | |
console.log('WORSE THAN EGGS!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Similarly How do we delete the user alerts created for the library for a specific user. Can uou suggest JSOM code for this