Quantcast
Channel: Microsoft Online: SharePoint Online forum
Viewing all articles
Browse latest Browse all 10096

Add items in a list which exists in another site collection on item updated event of list in some other site collection by using remote event receiver

$
0
0

Hi,

Can anyone let me know that how to Add items in a list which exists in another site collection on item updated event of list in some other site collection by using remote event receiver in SharePoint online.

I have given Tenant scope permissions to add-in and checked the checkbox 'Allow add-in to make app only calls' and creating Context by using below code:

                   string destinationSiteUrl = "Site coll2 URL";
                    Uri destinationSiteUri = new Uri(destinationSiteUrl);
                            //target realm of the tenant (This is constant per tenant)
                            string targetRealm = TokenHelper.GetRealmFromTargetUrl(destinationSiteUri);
                            //generate access token for destination site
                            string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal,              destinationSiteUri.Authority, targetRealm).AccessToken;
                            //get destination site context using access token
                            using (var destinationContext = TokenHelper.GetClientContextWithAccessToken(destinationSiteUrl, accessToken))
                            {
                                
                                var destinationlist = destinationContext.Web.Lists.GetByTitle("List1");
                                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                                ListItem newItem = destinationlist.AddItem(itemCreateInfo);
                                newItem["Title"] = "new Item";
                                
                                newItem.Update();

                                destinationContext.ExecuteQuery();

                            }

Thanks in advance.

Regards,

Abha Sharma


Viewing all articles
Browse latest Browse all 10096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>