1

Hi I've a event receiver that is scope to web.

On development environment, i deploy and it manage to attach to only a specific list, it will only trigger from this specific list.

However when i deploy to production, it manage to attach to the list(check from PowerShell, there's no duplicate), however it also attach to the site(my assumption), and it will trigger from any list.

I had deployed the same wsp twice, once is scope to site, after that i change it to scope to web and redeploy.

Result in production environment now:

  • event receiver will trigger from all list

  • on the specific list it will trigger twice, i believe because it(event receiver) is attached to that specific list and at the same time it is attached to the site, hence triggered twice. (there's no update in the ER, only sending email)

expected result:

  • only trigger on specific list and trigger only once

Elements.XML:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="/ISD/Lists/ICForm">
      <Receiver>
        <Name>Email_EventItemAdded</Name>
        <Type>ItemAdded</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>IC___Event_Receiver.Email_Event.Email_Event</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
      <Receiver>
        <Name>Email_EventItemUpdated</Name>
        <Type>ItemUpdated</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>IC__Event_Receiver.Email_Event.Email_Event</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>
</Elements>

Feature Manifest:

<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Scope="Web" Title="IC - Event Receiver Feature" Id="aef9e351-e707-4848-927d-6f5d525aab1a">
  <ElementManifests>
    <ElementManifest Location="Email Event\Elements.xml" />
  </ElementManifests>
</Feature>

Package.Template.XML:

<?xml version="1.0" encoding="utf-8"?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/">
<Assemblies>
<Assembly Location="IC - Event Receiver.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl Assembly="$SharePoint.Project.AssemblyFullName$"
Namespace="$SharePoint.Project.FileNameWithoutExtension$" TypeName="*" Safe="True"></SafeControl>
</SafeControls>
</Assembly>
</Assemblies>
</Solution>

Anyone experience issue like this? or any advice on how to solve this?

Thanks

nicker
  • 477
  • 2
  • 6
  • 20

1 Answers1

0

If you want to limit the event receiver attaches to specific list, use ListUrl to specific the list.

For example:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="/Lists/customlist">

And make sure you disable event firing when you update list item in proper event receiver, one thread for your reference

Lee
  • 5,305
  • 1
  • 6
  • 12
  • Hi thanks, as said i'd already attached to the list, means i already include ListURL to the specific list. issue is that beside attaching to the list, it attached to the site too – nicker May 22 '18 at 01:31
  • Have you disabled event firing? if you set ListUrl, won't make scene the ER attached to other lists, you could use PowerShell to confirm whether the ER attached to other lists. – Lee May 22 '18 at 01:52
  • If we scope to site, regardless whether we set ListUrl or not it will not attached to the list, but to the site. for my case i scope to web, and had set ListUrl, hence yes it shouldnt trigger from other list. On my dev server it is working fine, but in production it fires from everywhere. had check using powershell, on other list there's no event receiver attached, hence my guess it is attached to the site. disable event firing isn't the issue here, and anyway my ER doesn't update the list, it only sends email. – nicker May 22 '18 at 03:24
  • Seems you'd better confirm whether other custom logic deployed for production. (alert/workflow etc.) – Lee May 22 '18 at 09:36
  • Previously i'd deployed this event receiver as scope to site, then i redeploy again changing scope to web). I'm not sure if this is the cause, but is there away to locate if this event receiver is attach to site or anywhere else? so that i can delete? – nicker May 22 '18 at 10:38
  • Check this link https://pholpar.wordpress.com/2013/07/08/finding-and-removing-orphaned-event-receivers-using-powershell/, would be help. And disable the feature/ retract the solution to check whether the issue exists to confirm this caused by this solution. – Lee May 23 '18 at 05:10
  • 1
    Hi @Lee_MSFT, thanks for your help, after scanning site event receiver by assembly name, unfortunately i'm still not able to find it. However i'd recreate a project with all the same code, and redeploy, it is working as expected now. – nicker May 28 '18 at 01:52