remove space in a field in client end

Hi, could you kindly help below?

A text input field (of property T1) is defined in a section, and, also a button in the section with a click event action (e.g. run a DT) controlled by a when condition.

I set the when condition as: When → Other Property: T1 = “ABC”

My purpose is to run the action only if user input “ABC” in T1.

This works normally. However, if user input with some trailing spaces: "ABC ", then the when condition return false and the action is not done. I expect the action should be done.

Here may I know how I trim spaces in the “When → Other Property” condition? Pega does not allow me to use any function here as below, an error happen.

@MaxonL16591286 you could trim T1 before this action step and here you can just do T1=ABC.

@Anoop Krishna Hi, thanks. However, how?

how to trim T1 before this action step ?

If SetValue is used: it dose not support function call as well.

@MaxonL16591286 hey

Instead of other property, select when condition and inside this when trim the value and check condition.

Use stripNonAlphaNumeric function to trim all special characters and numbers from the given string

if you want to trim only spaces, use replaceAll function and replace space with empty.

Ideally, your when condition with expression builder should look like

@stripNonAlphaNumericChars(.T1)==“ABC”

Or

@replaceAll(.T1," “,”‘’)==“ABC”

This will not update clipboard with trimmed value.

@Anoop Krishna Remember? We discussed about some issue in past.

Values updated in previous action set will not consider updated values while checking some conditions in next action set due to no DOM refresh.

@BATTINIRAMESH Hi, Ramesh, agree that

“Values updated in previous action set will not consider updated values while checking some conditions in next action set due to no DOM refresh.”

We did not use data transform due to this issue.

However, not clear about your suggested solution.

“Instead of other property, select when condition and inside this when trim the value and check condition.”

Besides “other property”, only one option here: “when rule”, which will be also impacted by the DOM refresh issue.

My Pega version is 8.6.6.

@MaxonL16591286 no it won’t because, in when condition we are Just taking trimmed value on fly, we are not updating any property value.

Please try once

@MaxonL16591286 sure, please tell me this, should we ignore numbers too?

For suppose if we have “ABC12” Should the condition be true or false?

@BATTINIRAMESH No, I need not ignore numbers. So “ABC12” should make the condition to be false.

I just want to ignore spaces. Of course, if any leading spaces, they should be also ignored, like " ABC ", should make the condition to true.

Thanks.

@MaxonL16591286 you can use a data transform to do the same.

Action-> Run Data Transform

@BATTINIRAMESH ya right, I remember that. Thanks for pointing out​:+1:. @Maxon you can try the approach suggested by Ramesh, it should work.

@BATTINIRAMESH

Not understand your message.

Simply, could you share a sample that verified work normally?

Expected: If I input “ABC” even with any trailing spaces like "ABC " in the text field, an action will be performed when the button is clicked.

@BATTINIRAMESH Thanks, however, did you verify it?

Pls note, a when rule in an action set will be evaluated BEFORE the action set start, so, .T1 inside the when rule will not get the value user input before clicking button, even if you put a refresh in the action set.

Otherwise, it’s not difficult to think out to use a when rule to do the space trim.

@MaxonL16591286 why T1 will not get value? it will get, keep post value on Change of T1 in section and try.

@MaxonL16591286 can you please try the below solution. You can use DT to trim the actual property and do set value this actual property to another property. And you can use this property as the flag. You just need to have this property as hidden control in the UI.

https://support.pega.com/question/launching-local-action-when-condition-not-working

@MaxonL16591286 thanks for letting us know the approaches you have tried with the outcome. 2nd one is already a proven solution according to the link which I have shared, so you can go ahead with the same.

@MaxonL16591286 ok create a when rule with condition as below, and apply this when condition instead of other property.

@Anoop Krishna

Hi Anoop, thanks. Pls review below:

Both solutions from Ramesh and you should be fine. (Ramesh did not tell the whole solution at 1st time.)

Ramesh’s solution: (1) on Change of T1: PostValue (or refresh section) in order to sync T1 to clipboard. (2) In button click event, use a when rule to check value of T1 is space or not.

Because (1) and (2) using different action set, so the when rule in (2) can get the latest T1 value and the logic is correct. Pls note, we NEED NOT do any trim here, because Pega will auto trim T1 while sync T1 to clipboard.

Anoop’s solution: Instead of using two action sets, one is enough. NO need on Change of T1. Just button click event action set is needed, in which we need a bit complex solution that in the share link. It should be:

A. PostValue (or refresh section) in order to sync T1 to clipboard.

B. SetValue from T1 to a hidden text

C. Use when - “other property” to check the hidden text

Same, we NEED NOT do any trim here, as step A auto do it.

@MaxonL16591286 1st solution is not fine as Pega can not guarantee the running sequence of the two action sets.

@Anoop Krishna noted, thx. Just a complain that we need such a complex solution for such a simple logic.

Just curious that whether Pega will enhance the “action set/when condition” behavior?

It’s quite not intutive.