I have a custom workflow which is now working below that creates multiple records from a multi-line text field (line by line).
Problem: People will type in telephone numbers into this field in a list however some people put in spaces into phone numbers. I want to be able to remove any spaces in these phone numbers.
Another problem is that people put blank lines in the text field and this blank line will create a new record in the said custom workflow below.
I need to know how to manipulate the code below so that the mutliline text field data is cleansed before it creates the records.
So for example:
08888 888888
09888 888888
<Blank Line>
09988 888 888
<Blank Line>
<Blank Line>
<Blank Line>
Becomes
08888888888
09888888888
09988888888<<<<<<Array/Multiline is trimmed at this point.
Code I have used so far for the custom workflow is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk;
using System.Text.RegularExpressions;
namespace CreateLineRecords
{
public class CreateRecords : CodeActivity
{
[Input("Phone Numbers")]
[RequiredArgument]
public InArgument<string> LinesString { get; set; }
[Input("Billing Account")]
[RequiredArgument]
[ReferenceTarget("account")]
public InArgument<EntityReference> Accountfromorder { get; set; }
[Input("Order")]
[RequiredArgument]
[ReferenceTarget("salesorder")]
public InArgument<EntityReference> Orderfromorder { get; set; }
protected override void Execute(CodeActivityContext context)
{
IWorkflowContext workflowcontext = context.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(workflowcontext.InitiatingUserId);
var lines = LinesString.Get<string>(context).Split('\n').ToList<string>(); ;
foreach (var line in lines)
{
var lineEntity = new Entity("rp_line");
var accountforline = Accountfromorder.Get<EntityReference>(context);
var orderforline = Orderfromorder.Get<EntityReference>(context);
lineEntity["rp_cli"] = line;
lineEntity["new_billingaccount"] = accountforline;
lineEntity["new_order"] = orderforline;
service.Create(lineEntity);
}
}
}
}