- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2016 07:22 AM
Our team is creating a number of record producers that utilize the same Client Scripts and Business Rules. As of right now, we are just copying and pasting them individually into each record producer, but is wondering if there's a better way to do this. The way we're currently doing this could be a pain to update or maintain in the future. Is there a way to use UI Macros or something similar that would save the code and we can just call upon it in each of our record producers? That way, if changes in the code arise, we wouldn't have to update the code in each record producer.
Thanks!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2016 08:51 AM
I don't know the details of your requirements, but this is how you can create shareable code for catalog items, including Record Producers:
1. Create a new Variable Set
2. Create a new onLoad Client Script as part of that Variable Set and include the following code:
function onLoad() {
//this is just a placeholder, but is required
}
function u_sharedFunction1(){
//add your code here
alert("You called?");
}
function u_sharedFunction2(){
//add your code here
}
The onLoad() snippet is just a placeholder and does not need to contain anything, but is nonetheless required to be there. The u_sharedFunction1 and 2 are whatever shared functions you have. Add as much as you need. Adding them to the onLoad script makes them available within the Record Producers.
3. Add the Variable Set to whatever Record Producers needs it
4. Call one of the functions from a Client Script in one of your Record Producers. Example:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
u_sharedFunction1();
}
A "You called?" alert would appear on screen in the example above:
Now you have simple, shareable AND easily managed code available to your Record Producers without the overhead of Global UI Scripts. The code is only loaded for those catalog items you add the Variable Set to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2016 09:25 AM
It actually has to be an onLoad script in order to work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 07:36 AM
Hi Jim, do you know if this method still works in London? I am getting a similar error to peterraeves, except in the platform as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 08:11 AM
You can create a UI Macro variable in the variable set to contain the shared code:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<script>
function uiMacroSharedCode() {
alert("Running from the UI Macro");
}
</script>
</j:jelly>
BUT, that only works in the Desktop UI and not the Portal. The Portal does not render UI Macros. You would have to also created a Widget and associate it with the variable in order for the Portal to load it. Not sure what the Widget would contain though. Will try to look at that later.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 08:20 AM
Actually, in my example I am wanting to do have a reusable function for client scripts on the incident table. It's not a catalog item at all. So do I need to add a formatter to the form with this Jelly stuff?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2017 08:40 AM
When I do this on the portal, I get 'Error while running Client Script "": ReferenceError: my_function is not defined'. Both client scripts run on portal, the function just is not accessible any more. It works in service catalog. any idea why?