How do I reuse code between JavaScript queries?

I ended creating 4 action handler scripts for an application. All of these scripts use the same update code at the end of them. I would like to turn this code into a function and share it between the files so if I am updating things in the future I don't need to update all four files and maybe miss one.

If I do create this function, say in another JavaScript query, is there a way I can reference it in the four JavaScript queries?

@brettski

You can define custom JS code in scripts and styles, which I shared a visual of below. You can also define custom JS and/or CSS in your org settings. These functions can be called anywhere in your app!

Okay, thank you Lauren. So only on a global scale, not within app scope? I appreciate it.

Brett

Actually @lauren.gus I wasn't able to find where this is at. Please advise.

@brettski

If you click the three dots in the top right there is a dropdown:

Haha! I just made that same screen shot to show I found it (and for other's reference). Thank you.

Can this be accessed within a JavaScript query though?

@brettski

Yes, you should be able to :slightly_smiling_face:

Thank you. How would that look? When I tried to reference a function written in shared app the JavaScript query said it was not available. Thank you.

@brettski

Here is an example:

2 Likes