string fetch = this.FetchXmlString.Get(executionContext);
fetch = fetch.Replace(
"value=""",
"value="" + context.PrimaryEntityId.ToString() + """);
When I built it, its showing me the following error:
) expected,
; expected
Invalid expression term ')'
Invalid expression term ','
Only assignmen, Call, increment, decrement, and new object expressions can be used as a statement.
can I know what happen actually ?? how can I solve it ??
please help!! thank you!!
The following code is my Full Coding in C#:
namespace xyz.Crm.Workflow
{
using System;
using System.Activities;
using System.Linq;
using System.ServiceModel;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
public sealed class DokumentPositionen : CodeActivity
{
protected override void Execute(CodeActivityContext executionContext)
{
ITracingService tracingService = executionContext.GetExtension<ITracingService>();
if (tracingService == null)
{
throw new InvalidPluginExecutionException("Failed to retrieve tracing service.");
}
tracingService.Trace("Entered DokumentPositionen.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}",
executionContext.ActivityInstanceId,
executionContext.WorkflowInstanceId);
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
if (context == null)
{
throw new InvalidPluginExecutionException("Failed to retrieve workflow context.");
}
tracingService.Trace("DokumentPositionen.Execute(), Correlation Id: {0}, Initiating User: {1}",
context.CorrelationId,
context.InitiatingUserId);
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
OrganizationServiceContext orgcontext = new OrganizationServiceContext(service);
try
{
StringBuilder sb = new StringBuilder();
string fetch = this.FetchXmlString.Get(executionContext);
fetch = fetch.Replace(
"value=""",
"value="" + context.PrimaryEntityId.ToString() + """);
EntityCollection entityCollection = service.RetrieveMultiple(new FetchExpression(fetch));
if (entityCollection.Entities.Count > 0)
{
RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Attributes,
LogicalName = entityCollection.EntityName
};
RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse)service.Execute(retrieveEntityRequest);
if (retrieveEntityResponse.EntityMetadata.Attributes == null)
throw new Exception("null Wert für Attribute");
if (retrieveEntityResponse.EntityMetadata.Attributes.Count() == 0)
throw new Exception("0 Attribute");
if (entityCollection.Entities.Count == 0)
throw new Exception("0 Datensätze");
for (int i = 0; i < entityCollection.Entities[0].Attributes.Count - 2; i++)
{
tracingService.Trace("Suche Attribute mit : {0}", entityCollection.Entities[0].Attributes.ElementAt(i).Key);
AttributeMetadata am = retrieveEntityResponse.EntityMetadata.Attributes.Where(x => x.LogicalName == entityCollection.Entities[0].Attributes.ElementAt(i).Key).FirstOrDefault();
if (am != null && String.IsNullOrEmpty(am.DisplayName.ToString()) == false)
{
sb.Append(am.DisplayName.LocalizedLabels.First().Label + " ");
}
}
foreach (var entity in entityCollection.Entities)
{
sb.AppendLine();
for (int i = 0; i < entity.Attributes.Count - 2; i++)
{
if (entity.Attributes.ElementAt(i).Value is EntityReference)
{
tracingService.Trace("Attribute wird übersprungen weil Referenz");
}
else if (entity.Attributes.ElementAt(i).Value is Money)
{
sb.Append(((Money)entity.Attributes.ElementAt(i).Value).Value.ToString("0.00") + " ");
}
else if (entity.Attributes.ElementAt(i).Value is Decimal)
{
sb.Append(((Decimal)entity.Attributes.ElementAt(i).Value).ToString("0.00") + " ");
}
else
sb.Append(entity.Attributes.ElementAt(i).Value.ToString() + " ");
}
}
}
else
{
sb.AppendLine("Keine Belegpositionen vorhanden");
}
this.DokumentPositionenString.Set(executionContext, sb.ToString());
}
catch (FaultException<OrganizationServiceFault> e)
{
tracingService.Trace("Exception: {0}", e.ToString());
throw;
}
tracingService.Trace("Exiting DokumentPositionen.Execute(), Correlation Id: {0}", context.CorrelationId);
}
[Output("String with Positions")]
[Default("")]
public OutArgument<string> DokumentPositionenString { get; set; }
[RequiredArgument]
[Input("FetchXML")]
public InArgument<string> FetchXmlString { get; set; }
}
}
this is a Custom Workflow in MS CRM 2011
thank you!!