Validate user input in Script step - Flow Designer Action

Leandro Oliveir
Tera Contributor

Hello everyone,

 

In the following script, only the else condition is working. The first if condition is not.

LeandroOliveir_0-1699417308325.png

 

It's a script step of an action. It's simple my requiriment, If the user types a number with six digits, I concatenate it with two zeros at the beginning of this input, if not, I leave the input as the user types (the input already with the two zeros). But it's not working. 
What I'm missing?


Script:

 

(function execute(inputs, outputs) {

    try {

        var userID = inputs.user;

        if(userID.startsWith('00')) {
            inputs.user = userID;
            } else {
                inputs.user = '00' + inputs.user;
                }

        var utils = new VAResetPasswordUtils();
        inputs.user = inputs.user + "@teste.com.br";
        var user = utils.getUser(inputs);
        
        if (user.httpStatus == '200' ) {

            outputs.message = JSON.stringify(user);

            outputs.status = 'success'
            outputs.onpremiseuser = user.responseBody.onPremisesSyncEnabled || false;
            outputs.phone_number = user.responseBody.mobilePhone;
            outputs.account_enabled = user.responseBody.accountEnabled;
            outputs.display_name = user.responseBody.displayName

        } else {
            outputs.status = 'error'
            outputs.message = JSON.stringify(user);
        }

    } catch (e) {
        outputs.message = e.message;
        outputs.status = 'error'
    }


})(inputs, outputs);

 

 

The action it's working correctly, just the input validation doesn't work (the first if condition).

Bill Brown
Tera Contributor

Did you try and write your inputs.user to the log to see what data you are getting? 

Vishal Birajdar
Giga Sage

Hi @Leandro Oliveir 

 

Can you try using 'toString()' :

 

try {

        var userID = inputs.user.toString();   // use toString();

        if(userID.startsWith('00')) {
            inputs.user = userID;
            } else {
                inputs.user = '00' + inputs.user;
                }

 

 

Hi @Vishal Birajdar ,

I tried using toString() and it doesn't work. Still has the same problem: it passes directly to else condition.
The log shows like this:

LeandroOliveir_0-1699418142322.png

 

 

Hi @Leandro Oliveir 

 

If possible can you share screenshot of action with inputs...!!!