所在行:
Guid AlertsId = service.Create(NewAlert);
NewAlert["new_alertguid"] = "Spennende: " + AlertsId.ToString();
我正在尝试获取新创建的GUID。 但是什么也没发生。我没有GUID,工作流也不会失败。 它也不在该字段中写“ Spennende”。但是我看不到如何找出我做错了什么。
我该怎么解决。你们看到错了吗?
试图在同一字段中插入其他值。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
namespace WordCountWorkflow
{
public class WordCount : CodeActivity
{
[Input("Hvilket felt skal endres")]
public InArgument<string> FieldToChange { get; set; }
[RequiredArgument]
[Input("Tekst som skal telles")]
public InArgument<string> InputText { get; set; }
[Output("Antall tegn")]
public OutArgument<int> CountOfWords { get; set; }
protected override void Execute(CodeActivityContext context)
{
this.CountOfWords.Set(
context,
this.InputText.Get<string>(context).Split(
new char[] { ' ', '\r', '\n' },
StringSplitOptions.RemoveEmptyEntries).Length);
//------------------
ITracingService tracingService = context.GetExtension<ITracingService>();
IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
Entity NewAlert = new Entity("new_alerts");
NewAlert["new_name"] = "Navn på alert";
NewAlert["new_message"] = "Her er beskjed";
Guid AlertsId = service.Create(NewAlert);
NewAlert["new_alertguid"] = "Spennende: " + AlertsId.ToString();
}
}
}
我尝试更改为此:
ITracingService tracingService = context.GetExtension<ITracingService>();
IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
Entity NewAlert = new Entity("new_alerts");
Guid AlertsId = service.Create(NewAlert);
NewAlert["new_name"] = "Navn på alert";
NewAlert["new_message"] = "Her er beskjed " + AlertsId.ToString();
NewAlert["new_shortmessage"] = "Spennende: " + AlertsId.ToString();
但是随后一切都停止了。而且所有字段都没有填写。
答案 0 :(得分:2)
您可以在创建记录的GUID时使用以下代码
Entity NewAlert = new Entity("new_alerts");
NewAlert.Id = Guid.NewGuid();
NewAlert["new_name"] = "Navn på alert";
NewAlert["new_message"] = "Her er beskjed";
NewAlert["new_alertguid"] = "Spennende: " + NewAlert.Id.ToString();
Guid AlertsId = service.Create(NewAlert);
或者您可以创建新的对象,然后对其进行更新。
Entity NewAlert = new Entity("new_alerts");
NewAlert["new_name"] = "Navn på alert";
NewAlert["new_message"] = "Her er beskjed";
Guid AlertsId = service.Create(NewAlert);
Entity CompleteNewAlert = new Entity("new_alerts",AlertsId );
CompleteNewAlert ["new_alertguid"] = "Spennende: " + AlertsId.ToString();
service.Update(CompleteNewAlert );