Best practices for Client Scripts when migrating to Workspaces

Walt Janssens
Tera Contributor

We recently started migrating to Workspaces. In Client Scripts, we're encountering issues where getReference and GlideRecord queries no longer work without a callback function. Currently, we're able to make the scripts work, but they sometimes involve callback functions within callback functions, and so on. What are the best practices here? Should we create one Client Script that works for both environments, or would it be better to create new Client Scripts with UI Type Mobile / Service Portal, so that the new ones will only work in Workspaces and the original ones only work in the old environment.

1 REPLY 1

Deepak Shaerma
Kilo Sage

Hi @Walt Janssens 
Best Practices for Client Scripts::::::::
If you’re working in an environment that supports it, consider wrapping your calls in Promises and leveraging async/await for more readable asynchronous code. This can help avoid the “callback hell” situation.
-Break down complex operations into smaller functions. This not only makes your code cleaner and more manageable but also simplifies handling callbacks or promises.

So my suggestion here is for simple scripts, maintaining dual compatibility with environment checks might be manageable and preferable. For more complex interactions that significantly differ between environments, developing separate scripts may lead to better performance and easier maintenance.
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma