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).

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Leandro Oliveir Are you sure about passing the inputs in the following method. 

 var user = utils.getUser(inputs);

Not sure about the implementation of your getUser method but I am assuming it expects inputs.user

 var user = utils.getUser(inputs.user);

 

View solution in original post

6 REPLIES 6

Bill Brown
Tera Contributor

I tried to reply before but it it did not seem to work. Did you try and write inputs.user to the log to see what data you are getting?

 

Sandeep Rajput
Tera Patron
Tera Patron

@Leandro Oliveir Are you sure about passing the inputs in the following method. 

 var user = utils.getUser(inputs);

Not sure about the implementation of your getUser method but I am assuming it expects inputs.user

 var user = utils.getUser(inputs.user);