
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 07:50 PM - edited 11-07-2023 08:22 PM
Hello everyone,
In the following script, only the else condition is working. The first if condition is not.
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).
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 09:58 PM
@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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 08:02 PM
Did you try and write your inputs.user to the log to see what data you are getting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 08:04 PM
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;
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 08:15 PM - edited 11-07-2023 08:38 PM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 09:23 PM
If possible can you share screenshot of action with inputs...!!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates