Skip to content

Instantly share code, notes, and snippets.

@beckettkev
beckettkev / SPO List Alerts.js
Last active October 13, 2021 09:27
JavaScript for Adding a Document Library Email Alert for the loggged in User
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);
{"viewXml": "<View Name=\"{ABEA11C2-AD01-33CD-AACD-1F5A587A0CBB}\" DefaultView=\"TRUE\" MobileView=\"TRUE\" MobileDefaultView=\"TRUE\" Type=\"HTML\" DisplayName=\"All Items\" Url=\"/sites/nameofsite/lists/Name of list/AllItems.aspx\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ImageUrl=\"/_layouts/15/images/generic.png?rev=47\"><Query><OrderBy><FieldRef Name=\"ID\" Ascending=\"FALSE\"/></OrderBy></Query><ViewFields><FieldRef Name=\"Title\"/><FieldRef Name=\"Created\"/><FieldRef Name=\"Modified\"/><FieldRef Name=\"MyCustomColumn1\"/><FieldRef Name=\"MyCustomColumn2\"/><FieldRef Name=\"MyCustomColumn3\"/><FieldRef Name=\"MyCustomColumn4\"/></ViewFields><RowLimit Paged=\"TRUE\">30</RowLimit><JSLink>clienttemplates.js</JSLink><XslLink Default=\"TRUE\">main.xsl</XslLink><Toolbar Type=\"Standard\"/><Aggregations Value=\"Off\"/></View>"}
Patch('My Document Library Name', {
MyInternalLookupFieldName: {
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
// For illustrative purposes only - you would dynamically set this...
Value: "",
Id: -1
}
});
Patch('My Document Library Name', {
MyInternalLookupFieldName: {
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Value: MyLookupComboBox.Selected.Value,
// Notice the only additional property is the ID for lookups (otherwise it is the same as a choice value)
Id: MyLookupComboBox.Selected.ID
}
});
@beckettkev
beckettkev / PowerApp.Patch.Single.MMD.js
Last active November 28, 2019 17:45
Setting a single valued taxonomy column from a combo box
// Where 'My Document Library Name' is the name of your document library / list
Patch('My Document Library Name', {
// Where 'MyInternalTaxonomyFieldName' is the internal name of the Managed Metadata column in SharePoint
MyInternalTaxonomyFieldName: {
// Where MyComboSelectBox is the single select combo box containing the selected choice in your Power App
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedTaxonomy",
TermGuid: MyComboSelectBox.Selected.TermGuid,
WssId: MyComboSelectBox.Selected.WssId,
Label: MyComboSelectBox.Selected.Label,
Path: MyComboSelectBox.Selected.Path,
Patch('My Document Library Name', {
MyInternalChoiceFieldName: {
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
// Where 'MyChoiceComboBox' is the single select combox box in your Power App
Value: MyChoiceComboBox.Selected.Value
}
});
// You get the idea...
ForAll(
MyComboMultiSelectBox.SelectedItems,
Collect(
ChoiceValuesFromComboBox,
{
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Value: Value
}
)
// First of all we need to loop through each of the selected items in the combo box...
ForAll(
// Where 'MyComboMultiSelectBox' is your multi select combox box containing the selected items...
MyComboMultiSelectBox.SelectedItems,
Collect(
// Create a new collection called TaxonomyValuesFromComboBox
TaxonomyValuesFromComboBox,
{
// Create a new entry in the collection for each of the selected items...
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedTaxonomy",
@beckettkev
beckettkev / Example SetViewXml
Last active November 20, 2019 19:15
Example call to the RenderListDataAsStream endpoint
/_api/web/GetList(@a1)/Views(@a2)/SetViewXml()?@a1=%27%2Fsites%2Fmycustomsite%2FLists%2FMy%20List%27&@a2=%27aaeb6c8a%2Dd013%2D41ec%2D9e44%2Db39b203d0caf%27
@beckettkev
beckettkev / RenderListDataAsStreamPOSTheaders
Last active November 20, 2019 11:22
RenderListDataAsStream POST headers
content-type: application/json;odata=verbose
accept: application/json;odata=verbose