CRM Toast Notification含overrideContent请求报错及解决问询
CRM Toast Notification 含overrideContent的示例报错问题及解决办法
问题背景
我们在实现CRM的Toast Notification JavaScript功能时,使用官方文档中的第一个示例代码可成功向用户发送通知:
var SendAppNotificationRequest = new Example.SendAppNotificationRequest( title = "欢迎", recipient = "/systemusers(8d585985-e1f4-ed11-8818-0022483d019b)", body = "欢迎使用应用通知功能!", priority = 200000000, iconType = 100000000, toastType = 200000000, );
但使用包含overrideContent元素的第二个示例时,执行出现错误:
var SendAppNotificationRequest = new Example.SendAppNotificationRequest(title = "SLA 已严重超时", recipient = "/systemusers(8d585985-e1f4-ed11-8818-0022483d019b)", body = "分配给您的记录已严重超出SLA时限。", iconType = 100000003, toastType = 200000000, overrideContent = { "@odata.type": "#Microsoft.Dynamics.CRM.expando", "title": "**SLA 已严重超时**", "body": "案例记录[需全面检修(示例)](?pagetype=entityrecord&etn=incident&id=0a9f62a8-90df-e311-9565-a45d36fc5fe8)已严重超出SLA时限,已升级至您的经理处理。" } );
收到的错误信息如下:
"message": "Error identified in Payload provided by the user for Entity :'', ----> InnerException : System.ArgumentException: Stream was not readable.
问题排查与解决
通过查看Network标签中的JSON payload,发现参数出现错位导致赋值错误:
{ "Title":"SLA 已严重超时", "Recipient":"/systemusers(8d585985-e1f4-ed11-8818-0022483d019b)", "Body":"分配给您的记录已严重超出SLA时限。", "Priority":100000003, "IconType":200000000, "ToastType":[object Object], "Expiry":null, "OverrideContent":null, "Actions":null }
可见IconType、ToastType、OverrideContent的参数整体上移一位,最终导致OverrideContent为null。将变量声明改为逐个赋值的方式后,问题得到解决:
var SendAppNotificationRequest = new alya_shared.SendAppNotificationRequest(); sendAppNotificationRequest.Title = "SLA 已严重超时"; sendAppNotificationRequest.Recipient = "/systemusers(8d585985-e1f4-ed11-8818-0022483d019b)"; sendAppNotificationRequest.Body = "分配给您的记录已严重超出SLA时限。"; sendAppNotificationRequest.IconType = 100000003; sendAppNotificationRequest.ToastType = 200000000; sendAppNotificationRequest.OverrideContent = { "@odata.type": "#Microsoft.Dynamics.CRM.expando", "title": "**SLA 已严重超时**", "body": "案例记录[需全面检修(示例)](?pagetype=entityrecord&etn=incident&id=0a9f62a8-90df-e311-9565-a45d36fc5fe8)已严重超出SLA时限,已升级至您的经理处理。" };
内容的提问来源于stack exchange,提问作者user3676641
相关产品推荐
相关产品推荐

