storing and calling g:evaluate scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2016 12:51 PM
I am creating a front end portal that requires using g:evaluate to call on variables from different tables.
For example:
<g:evaluate var="jvar_user_name">
var gr = new GlideRecord('sys_user');
gr.get('sys_id', gs.getUserID());
gr.first_name;
</g:evaluate>
Is there a way to store a bunch of these somewhere and then call upon them as needed, much like UI Scripts and Style Sheets? If so, how would I go about doing this?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2016 05:35 PM
Hi David,
Take a look at the UI Macro cms_menu_functions
It defines a function that is then used in other UI Macros which are previously calling that UI Macro using: <g:cms_menu_functions />
Then the function defined is used in the script, I think setting global variables should also be fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2016 10:03 PM
Hi Laurent,
Thanks for your reply. I'm not sure I completely understand. When I open up cms_menu_functions, I see this:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate>
function canViewMenu(gr) {
if (gr.logged_on == true)
if (!gs.isLoggedIn())
return false;
if (gr.roles.nil())
return true;
return gs.getUser().hasRole(gr.roles);
}
</g:evaluate>
</j:jelly>
How would I apply this to other g:evaulate scripts that I have? Would I need a separate UI Macro for each g:evaluate?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2016 06:28 AM
You can see how it is used by searching in the UI Macros: XML contains : <g:cms_menu_functions />
To have these variables available in all your portal, I think you can include it in your portal header UI Macro, but I'm not 100% sure. The target UI marco would be: render_content_block_header