- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2015 04:12 AM
Hello Gurus,
I`ve created custom macros, which I want to initiate/call from within other macros or UI pages. However, one thing I am not sure about is "the phase" in which a nested macro should be initiated.. Should i be using <g or <g2 instead ? What is the best/recommended practice on this ?
thanks a lot for your help
Cheers
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2015 12:14 AM
Here goes the examples that probes the statement on the prior post:
Given a simple macro like the following:
<?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 var='jvar_now'>
gs.nowNoTZ();
</g:evaluate>
This macro current Date is: <input id="id_test" value='${jvar_now}' />
</j:jelly>
1 - In a form: The results are cached when used from a form. I reloaded the below form multiple times and the time displayed never changed.
2- In a UI Page: The results are NOT cached when used in a UI page. The time will change every time i reloaded a UI page from which I'm invoking the macro:
3- In a MOBILE view: The results are NOT cached. The time will change every time I reloaded the macro using the view path for mobile
So, having reviewed our examples, you should only use g1 when your results can be cached and been aware that these would not be cached if used from a UI Page or from a Mobile View.
I really hope this was helpful. I enjoyed building the example on the various views... so thanks for asking the follow up question!
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2015 07:04 AM
Hi Maros, don't read it that way. Try to read your macros code differently. Perhaps the best thing is if you read the macro as if you were the compiler:
You first only run the phase 1 code. phase 2 code is totally ignored on this phase. The end result is the output of the phase 1 code... and yes, phase 2 code could wrap phase 1 code, but that does not mean that it determines whether a phase 1 code should or should not be evaluated. By the time the phase 2 code runs the phase 1 was already evaluated and its respective html code output is already produced.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2015 02:20 AM
Berny,
thanks for you reply. However, have a look at the following code ( common occurrence in ServiceNow )
<g2:evaluate var='jvar_canRun'>
var answer = false;
answer;
</g2:evaluate>
<j2:if test="$[jvar_canRun]">
<g:macro_invoke macro='some_macro_to_be_exucted' /> <!-- how is this possible ? would not this execute even before the IF statement gets evaluated ??? -->
</j2:if>
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2015 06:49 AM
Hi Maros, using the example you shared above, lets assume for a second that now phase 1 is completed and the result of the some_macro_to_be_executed is the text Hello Maros!. The outcome after phase 1 and prior phase 2 will be the following:
<b>This is just a test to say...
<g2:evaluate var='jvar_canRun'>
var answer = false;
answer;
</g2:evaluate>
<j2:if test="$[jvar_canRun]">
Hello Maros!
</j2:if>
</b>
Note that at this point the phase 1 is now evaluated. Always keep in mind that the final outcome is to produce a valid html/javascript that the client can process at the client side. Having said that, lets take a look how the above will be evaluated in phase2...
jvar_canRun will be evaluated to false
and if jvar_canRun is false, then Hello Maros will not be shown and the output will be:
<b>This is just a test to say... </b>
Now... lets assume for a second that jvar_canRun evaluates to true
on this way the output will be
<b>This is just a test to say... Hello Maros! </b>
Now... on practical terms, why does this makes sense?
It makes sense because the below line in Phase 1 may always produce the same outcome so I it's better just to have its outcome cached.
<g:macro_invoke macro='some_macro_to_be_exucted' /> <!-- how is this possible ? would not this execute even before the IF statement gets evaluated ??? -->
Still, there may be some conditions on which we may want to control when the outcome of that macro is part of the final html/javascript we send to the client. For such cases is where it makes sense to wrap a phase code 1 around a phase 2 condition and let the phase 2 condition control whether what was cached is sent or not to our client.
I hope this helps
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2015 06:50 PM
Hi Maros, I believe that will depend if you have any code running in phase 1 which is dependent on your UI macro to run. If so, then you may want to use <g:macro_name>; otherwise, I believe you may be better off doing it in phase 2.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2015 09:40 PM
Hi Maros, do you believe we can close this thread by marking the responses as correct/helpful or do you have any further questions?
Thanks,
Berny