You can use a lookup table to do insert the same piece of code multiple times. If you look at some of the DashBoard U examples, you'll see this being put to use.
Here is a minimal example:
function saySomething(greeting, name)
{
ogscript.rename('NameLabel', greeting + ' ' + name + '!');
}
%const['GlobalScripts']['saySomething']%
saySomething('Hello', params.getValue('params.name', 0));
%const['GlobalScripts']['saySomething']%
saySomething('Good-bye', params.getValue('params.name', 0));#DashBoard