Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Regular expression (regEx) eating letters in CRM Workflow

Posted on by 15

Hello everyone, 

I'm relatively new in working with dynamics365 CRM for my company and also to this forum, so please be patient with me :) 

I created a workflow that is searching in accounts for double spaces in between names. Using regex is the only way I think, but I'm

having a problem! I use the pattern [  ]. to detect the double spaces and then replace it with $" and then in the next step I use \$ and replace it with nothing so there's only one space left. And it works great when there are double spaces. BUT if there aren't, for example when I execute the workflow a second time - it also kills the first letter of the name after the space ... ANY suggestions on that? :) 

*This post is locked for comments

  • Lord_Vader89 Profile Picture
    Lord_Vader89 15 on at
    RE: Regular expression (regEx) eating letters in CRM Workflow

    Hey Ravi thanks for your effort!

    Yes I tried this outside, I found out I just needed the right pattern. So [  ]. includes the double space, but when the workflow runs over it again or over something with on space at all, it takes the letter after the space with it.

    Now I use \s\s to detect two spaces (didn't know that expression before) and it works perfectly now!

    Thank you again :)

    Marius

  • Lord_Vader89 Profile Picture
    Lord_Vader89 15 on at
    RE: Regular expression (regEx) eating letters in CRM Workflow

    Thank you Matheus!

    This must be working as well, but found another way now :)

    I use \s\s as pattern so it only replaces the double spaces ! And it's working now perfectly.

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Regular expression (regEx) eating letters in CRM Workflow

    Hi,

    Try your regex outside of workflow and see if you observe the same behaviour. If yes, you need to fix that first. I don't think this has anything to do with workflow.

    Also, to find/replace double spaces, you could have also used the simple replace function. Refer below sample-

    =======

    public void GetAccounsWithDoubleSpaces()

           {

               using (service = new OrganizationServiceProxy(new Uri(_organizationURI), null, _credential, null))

               {

                   string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' >

                                          <entity name = 'account' >

                                               <attribute name='name'/>

                                               <filter type='and'>

                                                   <condition attribute='name' operator='like' value='%  %' />

                                               </filter>

                                           </entity>

                                      </fetch>";

                   var allAccount = service.RetrieveMultiple(new FetchExpression(fetchXml));

                   foreach (var acc in allAccount.Entities)

                   {

                       // Current Name

                       var currentAccountName = acc["name"];

                       Console.WriteLine(currentAccountName);

                       // Replace double spaces

                       var updateAccountName = acc["name"].ToString().Replace("  ", "");

                       Console.WriteLine(updateAccountName);

                       // Replace double space in the entity object

                       var accountUPD = new Entity(acc.LogicalName, acc.Id);

                       accountUPD["name"] = updateAccountName;

                       service.Update(accountUPD);                    

                   }

               }

           }

    ==================

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Regular expression (regEx) eating letters in CRM Workflow

    Hello, welcome to community,

    I think it better you to check if the string character it's really is empty, so you to do the RegexExp. In the case, the space be equal " "(Empty), you don't do nothing. If space be "  " (Two spaces empty), apply regexExp.

    I hope helpfull you !

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans