Question

How to persist the null value instead of special characters when user enters only special characters

Hi ,

I am working on a requirement where i need to persist the null value when user enters only special characters.

I am giving 2 scenarios here for more clarity :

Scenario 1:

First Name : @-=+|Ravi

this one am able to remove leading spl characters from a First Name property.

O/P : First Name : Ravi

Scenario 2 :

When user enters only special characters

First Name : @-=+|%

currently, this one is getting persisted in DB with spl chars, but that should not happend.

So, How can i persist the null value in DB instead of spl chars.

Please suggest is there any such regular expression which contains only special characters.

So that i can replace the regex with null value (" " )

Also attached screenshot for reference.

Thanks in Advance,

Ravi

***Edited by Moderator: Pallavi to update platform capability tags***

Comments

Keep up to date on this post and subscribe to comments

Pega
April 24, 2019 - 8:21am

Can you try this function 

stripNonAlphabeticChars

April 24, 2019 - 8:42am

Hi 

Can you try using below :

@String.pxReplaceAllViaRegex(<Property-Name>,"[^a-zA-Z0-9]"," ")

 

Hope this helps.

 

Regards

Bhavya

April 27, 2019 - 3:22am
Response to Bhavya_Incessant

Hi Bhavya,

Thanks for your response !!

On click of a save button, I should persist null value of all properties whichever contains only special chars on the work object.

Here, your regex function will work for specific property based on what property we referred in that function.

So, I am looking for a suggestion where all properties which contains only spl chars on the work object should be wiped out with null value.

 

Thanks,

Ravi

April 29, 2019 - 12:47am
Response to RavikumarM1512

Hi

If that is the case, then you need to create a common rule and use that for all properties.

 

Regards

Bhavya

Pega
April 26, 2019 - 8:20am

Hello Ravi,

If you want to replace all the special characters then you need to use the regular expression to match the special character. You can then use replaceAll method from String class to replace it with the space. I had tried a sample use case to achieve your requirement.

1. Create a Edit Input rule as shown below for the property which you want to replace special characters with null.

2. In RecplaceSpecialChars rules, use regular expression to match all the special characters and replace with space. Below is the code and screen shot for the same.

if (theValue.length() > 0)
{
 //use regular expression to match all the special characters and replace with space
 theValue = theValue.replaceAll("[^\\w]"," ");
}

3. Enter text with special characters like "@-=+|Ravi" and verify from database that the special characters are replaced with empty spaces.

4. Verify from database that the special characters are replaced with empty spaces. 

Hope this helps.

Regards,

Waseem Khan

 

Pega
April 26, 2019 - 9:43am
Response to khanw2

I have also tried by entering only special characters for the same property. Special characters got replaced by empty spaces. Please see below for the same.

Database:

Regards,

Waseem Khan

April 27, 2019 - 3:12am
Response to khanw2

Hi Waseem,

Thanks for your response !!

But , I have a doubt, Do we need to add this Edit Input rule for each  and every property wherever we need. 

Currently am a writing a function where properties are not starts with px,py and pz.

here is the sample code :

java.util.Iterator itr = myStepPage.values().iterator();

while(itr.hasNext())

{

                ClipboardProperty prop= (ClipboardProperty)itr.next();

                String propname = prop.getName();

  //          String proptype = prop.getTypeName();

try{

                  if(!((propname.startsWith("px")) || (propname.startsWith("py")) || (propname.startsWith("pz"))))

                  {             

                                                String propvalue = prop.toString();

                                                String newpropvalue="";

                                                String regexStr = pega_rules_utilities.getDataSystemSetting("CLSBL","BLPortfolio/SpecialCharacterSet");

                                                //String regexStr = "^[%+-=@|]+";

                                                java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regexStr);

                                                java.util.regex.Matcher matcher = pattern.matcher(propvalue);

                                                while (matcher.find())

                                                {

                                                  String replacementStr = "";

                                                  newpropvalue = matcher.replaceFirst(replacementStr);

                                                  prop.setValue(newpropvalue);

                  

                                                }

                                }

}

   catch(Exception e)

   {

                   oLog.error("Error in trimming special characters for Page - " + myStepPage + " and property name - " + propname);

                }

}

 

So , I will try with ur regex pattern.

 

Thanks,

Ravi

Pega
April 28, 2019 - 1:47am
Response to RavikumarM1512

Hello Ravi,

Yes you need to add this Edit Input rule for each and every property wherever you need. 

Regards,

Waseem Khan