Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

How to I remove spaces and blank lines from a multiline text field?

$
0
0

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

{

publicclassCreateRecords : CodeActivity

{

[Input("Phone Numbers")]

[RequiredArgument]

publicInArgument<string> LinesString { get; set; }

[Input("Billing Account")]

[RequiredArgument]

[ReferenceTarget("account")]

publicInArgument<EntityReference> Accountfromorder { get; set; }

[Input("Order")]

[RequiredArgument]

[ReferenceTarget("salesorder")]

publicInArgument<EntityReference> Orderfromorder { get; set; }

protectedoverridevoid 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 = newEntity("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);

}

}

}

}


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images