【发布时间】:2023-02-17 22:19:36
【问题描述】:
我在 SharePoint 中有一个列表,其中附加了一个同步事件接收器,用于响应列表项 (ItemUpdating) 的更改事件。还有一个事件接收器调用的 Azure 函数。该函数验证字段。问题是,如果字段通过验证,则函数运行一次,但如果验证未通过,则事件接收器运行函数六次。
using namespace System.Net;
param($Request, $TriggerMetadata);
Write-Output "Function started.";
$xmlDocument=[xml]$Request.Body;
$ListItemTitle = $xmlDocument.Envelope.Body.ProcessEvent.properties.ItemEventProperties.AfterProperties.KeyValueOfstringanyType[1].Value.InnerText;
$listName = $xmlDocument.Envelope.Body.ProcessEvent.properties.ItemEventProperties.ListTitle;
Write-Output $ListItemTitle;
Write-Output $listName;
$responseBody = @'
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ProcessEventResponse
xmlns="http://schemas.microsoft.com/sharepoint/remoteapp/">
<ProcessEventResult
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ChangedItemProperties
xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<ErrorMessage>Validation Error!</ErrorMessage>
<RedirectUrl i:nil="true"/>
<Status>CancelWithError</Status>
</ProcessEventResult>
</ProcessEventResponse>
</s:Body>
</s:Envelope>
'@;
if($ListItemTitle -eq "BadTitle"){
Write-Output "Validation error!";
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
Body = $responseBody;
ContentType = "text/xml";
StatusCode = [HttpStatusCode]::OK;
});
}
else{
Write-Output "Validation passed.";
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK;
});
}
如何在验证失败时让函数运行一次?
【问题讨论】:
标签: azure-functions sharepoint-online event-receiver