547
Views
5
Comments
Solved
How to check length of input widget and add leading zeros if length less than 10?
Application Type
Reactive

Hello everyone,

I am building a reactive app that I have integrated with SAP which takes a process order number as input. This process order should always be 10 digits in length so I have restricted the max length of the input widget to 10. Now sometimes, some process order numbers are less than 10 digits so what we need to do here is to check the length of the input widget and if length is less than 10 then add leading zeros to the process order to make it so that it is exactly equal to 10 digits every time. How do I do this? Appreciate the help!


Screenshot 2022-01-17 100538.png
2021-06-02 20-50-04
Márcio Carvalho
Solution

So I have made a little demo on how to do it.

I created a client action that will check that.


On that client action, I will get the length of the input and I will return a string with the number of zeros that should be returned.

When the client action output return to my submit output I concat(I use the contact functions to join two strings) the input value with the string with the leading zeros

Check here on this link if is that what you want. And I also shared the OML with the solution.

https://marcio-carvalho4.outsystemscloud.com/xc/InsertLeadingZeros?_ts=637780450935610385

I am using data type of string in everything. But I think you can control that after implementing my solution. 

Kind Regards,

Márcio

InsertLeadingZeros.oml
UserImage.jpg
ZK

Hi Mario,

Can you please guide me a bit more how to use the length function here. When I use the ConsumeTreatment button client action I am not sure how to use this length function with the input widget or with my variable in which this process order number is stored. Also, the second part to this is to add leading zeros to the process order number if length is less than 10, how do I do that?

2021-06-02 20-50-04
Márcio Carvalho

You can see the length of the input, then you take the length of the input. And do 10-length(input). with that you will know how much zeros you will need to add. then you need to create an aux variable to append the remaining number of zeros to the value using a for each.

Thats the way i am seeing how to do it.

UserImage.jpg
ZK

I did it like this. Checked for length of input process order variable. If it is equal to 9 then I just add a "0" with my variable. Is this correct or the best way to do it? 


UserImage.jpg
ZK

This shows the assign that I used.

2021-06-02 20-50-04
Márcio Carvalho
Solution

So I have made a little demo on how to do it.

I created a client action that will check that.


On that client action, I will get the length of the input and I will return a string with the number of zeros that should be returned.

When the client action output return to my submit output I concat(I use the contact functions to join two strings) the input value with the string with the leading zeros

Check here on this link if is that what you want. And I also shared the OML with the solution.

https://marcio-carvalho4.outsystemscloud.com/xc/InsertLeadingZeros?_ts=637780450935610385

I am using data type of string in everything. But I think you can control that after implementing my solution. 

Kind Regards,

Márcio

InsertLeadingZeros.oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.