web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Regular expression (regEx) eating letters in CRM Workflow

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    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 !

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Lord_Vader89 Profile Picture
    15 on at

    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.

  • Lord_Vader89 Profile Picture
    15 on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans