Customer Engagement & Dynamics CRM Forum

Expand all | Collapse all

How do you check for a blank space?

  • 1.  How do you check for a blank space?

    Posted May 29, 2019 02:13 AM
    Hey all!

    Trying to make a business rule that checks for the existence of a period or blank space in a Contact's last name field, then display an error. It's catching the periods but missing spaces. At first I tried just using a space and alt+160 character but those didn't validate. Some random google searching suggested using * *, which validates but doesn't actually display the error.

    Here's what I'm trying. Rules are OR'd:

    Ultimately going for something like this:

    Any ideas? Thanks for your time!

    ------------------------------
    Mike Prill
    Team Rubicon USA
    Los Angeles CA
    ------------------------------


  • 2.  RE: How do you check for a blank space?

    TOP CONTRIBUTOR
    Posted May 30, 2019 04:43 PM
    JavaScript.  But if you find a way to do it in a business rule, I'm all ears.

    ------------------------------
    Ryan Perry
    Business Systems Analyst
    Auric Solar
    ------------------------------



  • 3.  RE: How do you check for a blank space?

    MICROSOFT MVP
    Posted May 31, 2019 03:04 PM
    Use JS, but if you want to make your eyes bleed, you could create a business rule for each permutation of letters (Let's pray that it isn't case sensitive)

    if(lastName Contains "a a" OR lastName Contains "a b" OR lastName Contains "a c" ... lastName Contains "z x" OR lastName Contains "z y" OR lastName Contains "z z")

    pretty sure the UI would max out on the number of ORs... so you may have to create multiple Business Rules (like one for each starting letter)..

    But that would be a horrible idea... Just write some JS.

    ------------------------------
    Daryl LaBar
    President, MVP
    Gap Integrity
    Fishers IN
    ------------------------------



  • 4.  RE: How do you check for a blank space?

    TOP CONTRIBUTOR
    Posted May 31, 2019 06:00 PM
    @Daryl LaBar, Hilarious response... But then I got thinking. The UI doesn't let you save a simple " " into a conditional statement (or anywhere else, really).  So, for the broader question: If Business Rules are basically just Javascript written via a simplified UI, a la WSYWIG editor, ​​​​is it possible to edit the code the UI business rule editor produces? This would be analogous to editing the FetchXML created by the Advanced Find editor.

    Just curious.  I'd write JS for this, but in some cases it would be nice to be able to add a " " into code snippets created by the UI.

    ------------------------------
    Ryan Perry
    Business Systems Analyst
    Auric Solar
    ------------------------------



  • 5.  RE: How do you check for a blank space?

    Posted Jun 11, 2019 01:45 PM
    Edited by Nicholas Cole Jun 11, 2019 01:46 PM
    Agree with the rest of the team JS is really going to be your friend here, and much quicker than anything in the business logic editor.

    Code should be very straightforward as well something simple like the following. You will have to verify it will work for your scenario, or adjust as needed.

     //get value of last name - assign to new field
    var lastname = Xrm.Page.getAttribute("lastname").getValue();

    //look for "." or blank spaces
    if (lastname.includes(".") || lastname.includes(" "))
    {
    alert("A period or blank space has been detected, if this person does not yet have a TR email this may mess up the UPN. Please correct in the Contact record prior to submitting.");
    }

    ------------------------------
    Nicholas Cole
    Enterprise Solutions Developer
    SMC3
    Peachtree City GA
    ------------------------------



  • 6.  RE: How do you check for a blank space?

    Posted Jun 11, 2019 04:25 PM
    Thank you @Nicholas Cole and everyone else for the detailed explanation. I think that will work​, cheers!

    ------------------------------
    Mike Prill
    Team Rubicon USA
    Los Angeles CA
    ------------------------------



If you've found this thread useful, dive deeper into User Group community content by role