Dynamic block contents and conditions not working with <g:content_block>?

samurai_c
Kilo Explorer

I'm attempting to include a dynamic content block in a layout via <g:content_block type="content_block_programmatic" id="c29676280f1e8600116be388b1050e50"/> in order to have it appear across an entire site (preventing me from having to add it to every page on the site manually). However, both the contents of the dynamic content block and the condition don't seem to be evaluating properly.

The condition is simply to display the block only if a user is signed in, and looks like:

function userNotLoggedIn() {

      if(gs.getUserName() === "guest") {

                  answer = true;

      } else {

                  answer = false;

      }

}

userNotLoggedIn();

whereas the dynamic content gets some URL parameters in order to allow for a redirect post-authentication:

<g:evaluate var="jvar_site_and_page" jelly="true">

      var page = new GlideRecord('content_page');

      page.get('${RP.getParameterValue('sysparm_sys_id')}');

      page.content_site.url_suffix + '/' + page.url_suffix;

</g:evaluate>

When the block is simply added to a page like other content, everything functions perfectly. It's only when I use the g:content_block method of rendering the block that things don't seem to work as they should.

Any suggestions? I'm not entirely sure that I'm even going about this problem in the right way, but I'm really looking for a way to not need to manually add this block to every single page in the site.

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I don't think it will evaluate your condition if you include it hardcoded in the layout, so I would just add an if statement directly in your layout. Something like:



<j:if test="${gs.getUserName() === 'guest'}">


      <g:content_block type="content_block_programmatic" id="c29676280f1e8600116be388b1050e50"/>


</j:if>


View solution in original post

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I don't think it will evaluate your condition if you include it hardcoded in the layout, so I would just add an if statement directly in your layout. Something like:



<j:if test="${gs.getUserName() === 'guest'}">


      <g:content_block type="content_block_programmatic" id="c29676280f1e8600116be388b1050e50"/>


</j:if>


Thanks! After fixing some bugs of my own, this ended up doing exactly what I needed it to.


I am facing the same issue. How did you end up passing "RP.getParameterValue()" to your hardcoded block on the layout?