Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Automations Script to verify a value output is correct based on Length

Topic Labels: Automations
Solved
Jump to Solution
900 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Eddie_Kaeser
6 - Interface Innovator
6 - Interface Innovator

Any assistance would be greatly appreciated! 

I have a Serial Number (SN#) that is labeled "Locker Name". I want to make sure that the SN# is 7 Characters/Digits before finishing the automation as sometimes it get typed in wrong. the SN# format is NS01234 or NS00123. People leave off the 0's from time to time. i want to create a new record with this number in a new table. Linking is not option here. Here is what i am trying to do but i am getting this error: 

TypeError: Cannot read properties of undefined (reading 'length')
at main on line 4     if (sn.length === 5) {     
 
i guess i am asking how to get the Length of the value to read so that i can achieve this??
 
 

let sn = input.config.LockerName;
let updatedSN = '';

if (sn.length === 5) {
updatedSN = 'NS00' + sn.slice(-3);
} else if (sn.length === 6) {
updatedSN = 'NS0' + sn.slice(-4);
} else if (sn.length === 7) {
updatedSN = sn;
} else {
updatedSN = 'Invalid SN#';
}

output.set('updatedSN', updatedSN);

1 Solution

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

Try adding a "()" to your "input.config", so:

let sn = input.config().LockerName;
let updatedSN = '';

if (sn.length === 5) {
updatedSN = 'NS00' + sn.slice(-3);
} else if (sn.length === 6) {
updatedSN = 'NS0' + sn.slice(-4);
} else if (sn.length === 7) {
updatedSN = sn;
} else {
updatedSN = 'Invalid SN#';
}

output.set('updatedSN', updatedSN);

A non scripting alternative could be asking your users to just key in the number and you can add the appropriate prefix via a formula field instead

See Solution in Thread

2 Replies 2
TheTimeSavingCo
18 - Pluto
18 - Pluto

Try adding a "()" to your "input.config", so:

let sn = input.config().LockerName;
let updatedSN = '';

if (sn.length === 5) {
updatedSN = 'NS00' + sn.slice(-3);
} else if (sn.length === 6) {
updatedSN = 'NS0' + sn.slice(-4);
} else if (sn.length === 7) {
updatedSN = sn;
} else {
updatedSN = 'Invalid SN#';
}

output.set('updatedSN', updatedSN);

A non scripting alternative could be asking your users to just key in the number and you can add the appropriate prefix via a formula field instead

Test ran successfully!!!
 
Thank you so very much! 
 
~ED~