- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi
I have added one if condition on UI page which is failing. Pasting the code below and have highlighted in red , any help would be appreciated
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The issue seems to be how those server-side values are exposed to Jelly. In your first <g:evaluate> you compute baseTable, scope, etc., but you never assign any of them to a Jelly variable. In Jelly, <g:evaluate var="X">...</g:evaluate> only publishes the return value of that block (the last expression) into the single variable X. Local variables like baseTable created inside that block aren’t visible to your later <j2:if> tests, so an expression like baseTable == 'kb_knowledge' evaluates against an undefined symbol and the condition fails.
<!-- Make scope available to Jelly -->
<g:evaluate var="jvar_scope" jelly="true">
new GlideRecord(jelly.jvar_target_table).getTableScope();
</g:evaluate>
<!-- Make base table available to Jelly -->
<g:evaluate var="jvar_base_table" jelly="true">
new TableUtils(jelly.jvar_target_table).getAbsoluteBase();
</g:evaluate>
<!-- Role check as a boolean Jelly var -->
<g:evaluate var="jvar_has_kb_writer" jelly="true">
gs.hasRole('sn_hr_core.kb_writer');
</g:evaluate>
<!-- Scenario 1: task or cmdb-derived base table, and not HR scope -->
<j2:if test="$[((jvar_base_table == 'task' || jvar_base_table.contains('cmdb')) && !jvar_scope.contains('sn_hr'))]">
<h3 style="text-align:center;font-size:15px;font-weight:bold;">
Restrict the file upload of size more than 10 MB.
</h3>
</j2:if>
<!-- Scenario 2: kb_knowledge base table and user is NOT a KB writer -->
<j2:if test="$[(jvar_base_table == 'kb_knowledge' && !jvar_has_kb_writer)]">
<h3 style="text-align:center;font-size:15px;font-weight:bold;">
Restrict the file upload of size more than 10 MB.
</h3>
</j2:if>
ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.
ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ
ꜱʀᴇᴇʀᴀᴍ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi there @Tanya10 , Here try this jelly script and let me know how it goes.
<g:evaluate var="scope" jelly="true">
var gr = new GlideRecord(jelly.jvar_target_table);
gr.getTableScope();
</g:evaluate>
<g:evaluate var="baseTable" jelly="true">
var tableUtils = new TableUtils(jelly.jvar_target_table);
tableUtils.getAbsoluteBase();
</g:evaluate>
<g:evaluate var="jvar_attachrole" jelly="true">
gs.hasRole('sn_hr_core.kb_writer');
</g:evaluate>
Scenario 1: Task or CMDB-based table, and not in HR scope
<j2:if test="$[((baseTable.indexOf('task') != -1 || baseTable.indexOf('cmdb') != -1) && scope.indexOf('sn_hr') == -1)]">
<h3 style="text-align: center; font-size: 15px; font-weight: bold;">
Restrict the file upload of size more than 10 MB.
</h3>
</j2:if>
Scenario 2: On kb_knowledge table, user does NOT have writer role
<j2:if test="$[(baseTable == 'kb_knowledge' && jvar_attachrole == false)]">
<h3 style="text-align: center; font-size: 15px; font-weight: bold;">
Restrict the file upload of size more than 10 MB.
</h3>
</j2:if>
If this answer helps you in any way make sure to Mark this as accepted solution and give a thumbs up this will also benefit others as well.
Regards.
Saurabh V.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The issue seems to be how those server-side values are exposed to Jelly. In your first <g:evaluate> you compute baseTable, scope, etc., but you never assign any of them to a Jelly variable. In Jelly, <g:evaluate var="X">...</g:evaluate> only publishes the return value of that block (the last expression) into the single variable X. Local variables like baseTable created inside that block aren’t visible to your later <j2:if> tests, so an expression like baseTable == 'kb_knowledge' evaluates against an undefined symbol and the condition fails.
<!-- Make scope available to Jelly -->
<g:evaluate var="jvar_scope" jelly="true">
new GlideRecord(jelly.jvar_target_table).getTableScope();
</g:evaluate>
<!-- Make base table available to Jelly -->
<g:evaluate var="jvar_base_table" jelly="true">
new TableUtils(jelly.jvar_target_table).getAbsoluteBase();
</g:evaluate>
<!-- Role check as a boolean Jelly var -->
<g:evaluate var="jvar_has_kb_writer" jelly="true">
gs.hasRole('sn_hr_core.kb_writer');
</g:evaluate>
<!-- Scenario 1: task or cmdb-derived base table, and not HR scope -->
<j2:if test="$[((jvar_base_table == 'task' || jvar_base_table.contains('cmdb')) && !jvar_scope.contains('sn_hr'))]">
<h3 style="text-align:center;font-size:15px;font-weight:bold;">
Restrict the file upload of size more than 10 MB.
</h3>
</j2:if>
<!-- Scenario 2: kb_knowledge base table and user is NOT a KB writer -->
<j2:if test="$[(jvar_base_table == 'kb_knowledge' && !jvar_has_kb_writer)]">
<h3 style="text-align:center;font-size:15px;font-weight:bold;">
Restrict the file upload of size more than 10 MB.
</h3>
</j2:if>
ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.
ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ
ꜱʀᴇᴇʀᴀᴍ
