Custom Script Converter: What can you do with it?

Hi community!

Following the discussion we had in this thread, I wanted to re-introduce the Custom Script Converter.
Although the help center article gives some examples about how to use it, let’s all share in this thread your tips & tricks where this converter made your life easier.

I’ll start with the one that enables to trim a text on both hands, based on a fixed number of starting & ending characters to remove.

The script below removes the first 10 characters and the last 3 ones. Adapt the figures to your own needs.

var t = INPUT.substring(10);
var t2 = t.substring(0, t.length - 3)
t2

So, what’s your favorite usage of that converter?

PS : don’t forget to check the samples in the help center articles:

1 Like

“If Field is Blank” Converters:

I believe I learned two ways to do this, one from @AlexL and the other from @Mihai I believe:
This one works best for all players, including tablets. (I think android values technically are not ‘blank’, that’s why the one below works best for those)

if (INPUT.length < 1)
false;
else
true;

This works well for windows players

Is Blank for only windows I believe…

if(INPUT=="")
“False”;
else
"True";
2 Likes

Is there any way to extract the file name from a file path, and add ", " (that’s comma,space) to it? I’m using this to track a list of picture-names that someone has selected using the Concatenate IA, and write it to one cell in Excel.

Currently I have a work around that is working (thanks to @Seb as always), but I’m hoping for something a little cleaner.

An example is this:
INPUT: D:\IntuiFace\MedMtgImages-PhotoSelector\Files\InterfaceAssets\FileSystemBrowsingJS\Images\18ADA_00001.jpg

DESIRED OUTPUT: 18ADA_00001.jpg,

It’s possible the number of characters in the file name could vary depending on the file. I was hoping there’d be a way to extract it by a delimiter, but there isn’t currently a selection for that type of slash “\”.

Thanks for any ideas!

Hi @AlexB,

I couldn’t resist to answer you tonight on this one, since you’ll see as easy it can be, when you know how to write a little JavaScript :slight_smile:

Here’s the code for your converter:

INPUT.substring(INPUT.lastIndexOf("\\")+1)

It basically finds the last index of the \ character in the INPUT string (still need to escape this special character, thus the \ in the code) and returns what’s after this index, +1 not to have the \ in the returned string.

Give it a try and confirm me it does what you were looking for :wink:

3 Likes

You’re awesome! I’ll give it a try and report back. Is there a way to build in a comma and a space after the last character too? That way it’ll look like a nice list when it gets written to the excel cell.
Would I just add ", " to it?

INPUT.substring(INPUT.lastIndexOf("\\")+1) + ", "

:wink:

2 Likes

@Alex, @Seb
Thanks to you both, it works GREAT!

Follow up question for future use of this expression: If I wanted to get the X-th index, instead of the last index…what would that look like?

Use this:

folders = INPUT.split("\\");
folders[folders.length-2];

Quick explanation: the split command will break down the line into an array of elements, using “\” as separator.
folder[X] will display the Xth element of this array and I use folders.length-2 to target the 2nd before the end in this array.

Enjoy :wink:

1 Like

Very cool Alex, thanks for sharing this! Going to save this in my converter tools doc.

1 Like

By the way, I think @Seb and @Alex should host a Javascript Masterclass for everyone.

1 Like

I’ll pass on that, I only have a small knowledge about “vanilla” Javascript, I’d prefer to host cooking lessons :wink:

1 Like

In that case, please call it, “Cooking with Camacho”

3 Likes

One thing i have thought of over the weekend.

Is it possible to have an animated/faded gradient rectangle with a 3 tone colour?

Could this be done with Javascript?

Like the CSS alternative https://www.gradient-animator.com/

GO… @Alex @Seb?

2 Likes

Oo! Yes! I’d like to play around with that in future projects! :slight_smile:

By the way, I think @Seb and @Alex should host a Javascript Masterclass for everyone.

Yes please! I know nothing about Javascript, but I would love to learn.

1 Like

Animating a gradient isn’t something that can be done today, as far as I know, since you currently can’t bind the gradient properties to anything.

@megan and @AlexB you could start by having a look at tutorials here: https://www.w3schools.com/js/ :wink:

1 Like

Thanks, @Seb!

That’s a cool effect, @Louie_Smith. I’d love to use that in IF someday. Thanks for sharing.

@Seb, I actually bought a beginners course some time ago, (on Udemy) but IF is keeping me too busy to go through the course! Haha, maybe that’s a good thing?

2 Likes