Pergunta

Eu estava usando um fluxo de trabalho para alterar nomes de arquivos para algum texto e o ID SP, mas isso causou problemas porque os fluxos de trabalho podem levar vários minutos para ser concluído.Eu gostaria de fazer isso durante o itemadding, mas tenho 99,999% de certeza que isso não é possível, pois o ID provavelmente não é atribuído até que o documento seja carregado.Eu acho que posso usar itemAdicionado, mas não sei quanto tempo isso pode demorar para começar.São uma dessas ideias razoáveis?

Foi útil?

Solução

This sort of task is more suited to an event receiver. The itemAdded approach will certainly give you access to the ID. An event receiver does not have the typical delay you see with Workflows, it fires right away.

One issue you can experience with ItemAdded events is that they run asynchronously. What this means is that the control is returned to the UI while the Event Receiver is kicked off. This can cause situation where the event receiver is not quite done processing before the display returns to the user, and they won't see the updated values until they refresh the page.

The solution to this is to set the mode for the ItemAdded event receiver to Synchronous in the Elements.xml file for the event receiver using :

  <Synchronization>Synchronous</Synchronization>

In context:

<Receiver>
  <Name>Test_ListEventReceiversItemAdded</Name>
  <Type>ItemAdded</Type>
  <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
  <Class>TestEventReceivers.Test_ListEventReceivers.Test_ListEventReceivers</Class>
  <Synchronization>Synchronous</Synchronization>
  <SequenceNumber>10000</SequenceNumber>
</Receiver>

With the Synchronous mode, the display won't return to the user until the processing is complete.

Outras dicas

You can do that in ItemAdded and make it synchronous so it will fire and execute in the same thread after ItemAdding is finished.

You can make an after event syncronous when you define it in your solution, or you can do it with code or PowerShell script.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top