Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Page not working in scoped application

Rakesh50
Mega Sage

Hi,

We have a UI page that works fine in the global application. However, when we copied that UI script and created it in a scoped application to use it, it is not working and is returning null. Specifically, we are getting the value edgeEncryptionEnabledForAttachments as null. Can anyone please suggest a solution? Please review the code below for reference."

 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<j:set var="jvar_target_sys_id" value="${JS:RP.getWindowProperties().get('target_sys_id')}" />
	<j:set var="jvar_target_table" value="${JS:RP.getWindowProperties().get('target_table')}" />
    <j:set var="jvar_attachment_disabled" value="${RP.getWindowProperties().get('attachment_disabled')}" />
	<g:evaluate var="sysparm_id">
		var companyID = RP.getWindowProperties().company_id;
		var engagementID = RP.getWindowProperties().engagement_id;
		var pracType= RP.getWindowProperties().practice_type;
		var accessType= RP.getWindowProperties().target_access_type;
		<!-- console.log("companyID*****"+companyID+"engagementID*****"+engagementID); -->
		gs.info("companyID*****"+companyID+"engagementID*****"+engagementID);
	</g:evaluate>
	<!-- <script>
    var companyID = "${JS: RP.getWindowProperties().get('company_id')}";
    console.log("bulk upload " + companyID);
    var engagementID = "${JS: RP.getWindowProperties().get('engagement_id')}";
    var pracType = "${JS: RP.getWindowProperties().get('practice_type')}";
    var accessType = "${JS: RP.getWindowProperties().get('target_access_type')}";
</script> -->

    <j:set var="jvar_sc_override" value="${RP.getWindowProperties().sc_override}" />
	<j:set var="jvar_show_link" value="true" />
	<j:if test="${gs.getProperty('glide.ui.disable_attachment_view') == 'true'}">
		<j:set var="jvar_show_link" value="false" />
	</j:if>
	<input type="hidden" id="ni.show_attachment_view" name="ni.show_attachment_view"
		value="${jvar_show_link}" />
	<j:set var="jvar_show_link_popup" value="true" />
	<j:if test="${gs.getProperty('glide.ui.attachment_popup')=='false'}">
		<j:set var="jvar_show_link_popup" value="false" />
	</j:if>

   <!-- Check no_attachment attribute in order to override if necessary. -->
   <g:evaluate var="jvar_no_attachment" jelly="true">
		var gr = new GlideRecord(jelly.jvar_target_table);
		gr.getED().getBooleanAttribute("no_attachment");
	</g:evaluate>

	<!-- Check if attachements are edge encrypted to show Download all only is not edge encrypted. -->
	<g:evaluate var="jvar_attachments_edge_encrypted" jelly="true">
		var gr = new GlideRecord(jelly.jvar_target_table);
		gr.getED().hasAttachmentsEncrypted();
	</g:evaluate>

	<g:evaluate var="jvar_have_not_available_attachments" jelly="true">
		var count = new GlideAggregate('sys_attachment');
		count.addQuery('table_name', jelly.jvar_target_table);
		count.addQuery('table_sys_id', jelly.jvar_target_sys_id);
		count.addQuery('state', 'not_available');
		count.addAggregate('COUNT');
		count.query();
		count.next() &amp;&amp; (count.getAggregate('COUNT') > 0);
	</g:evaluate>
	
	<g:evaluate var="jvar_kmfcleprop" jelly="true">
		gs.getProperty('glide_encryption.cle_replatforming_with_kmf');
	</g:evaluate>

	<!-- Store if attachements are edge encrypted for use in javascript -->
	<script>
		var edgeEncryptionEnabledForAttachments = '${jvar_attachments_edge_encrypted}';
	</script>

	<g:evaluate var="jvar_cloudedge_invalid" jelly="true">
		<!-- If attachments are edge encrypted and not edge session -->
		(jelly.jvar_attachments_edge_encrypted == "true") ${AMP}${AMP} !gs.isEdgeEncryptedSession();
	</g:evaluate>

   <!-- Check Users Ability to Attach -->
   <g:evaluate var="jvar_attachrole" expression="gs.getProperty('glide.attachment.role')" /> 

   <g:evaluate var="jvar_can_write_to_record" jelly="true">
	   (jelly.jvar_sc_override == 'true') ||
	   new AttachmentSecurity().canWriteTarget(jelly.jvar_target_table, jelly.jvar_target_sys_id);
   </g:evaluate>

   <j:if test="${jvar_attachment_disabled == 'true'}" >
        <j:set var="jvar_can_write_to_record" value='false' />
   </j:if>

   <g:evaluate var="jvar_email_client_override" jelly="true">
   		var ret = jelly.sysparm_this_url.startsWith('email_client.do');
   		ret;
   </g:evaluate>

   <!-- Store parent sys_id for use in javascript -->
   <script>
		var attachmentParentSysId = '${jvar_target_sys_id}';
   </script>

   <j:set var="jvar_can_add_attachments" value="false" />
   <j:set var="jvar_can_edit_attachments" value="false" />

   <j:if test="${jvar_email_client_override == 'true'|| jvar_sc_override == 'true'}" >
   		<j:set var="jvar_can_add_attachments" value="true" />
                <j:set var="jvar_can_edit_attachments" value="true" />
   </j:if>
   <j:if test="${jvar_email_client_override == 'false'}">
	   	<j:if test="${jvar_no_attachment == 'false'}">
	   		<j:if test="${jvar_can_write_to_record == 'true'}">
	   			<j:set var="jvar_can_edit_attachments" value="true" />
	   			<j:if test="${jvar_session.hasRole(jvar_attachrole)}">
	   				<j:set var="jvar_can_add_attachments" value="true" />
				</j:if>
			</j:if>
		</j:if>
	</j:if>

    <j:if test="${jvar_attachment_disabled == 'true' || jvar_cloudedge_invalid == 'true'}" >
        <j:set var="jvar_can_add_attachments" value="false" />
        <j:set var="jvar_can_edit_attachments" value="false" />
    </j:if>

	<input type="hidden" id="ni.show_rename_link" name="ni.show_rename_link"
		value="${jvar_can_add_attachments}" />

	<input type="hidden" id="ni.show_attachment_popup" name="ni.show_attachment_popup"
		value="${jvar_show_link_popup}" />
	<div id="alert_container"></div>
	<table width="100%" style="table-layout:fixed;">
		<tbody>
			<j:if test="${jvar_can_add_attachments}">
				<tr>
					<td>
						<div class="caption" style="display:none;">
							<span>${gs.getMessage('Choose a file to attach')}:</span>
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<FORM id="sys_attachment" name="sys_attachment" action="sys_attachment.do?sysparm_record_scope=$[jvar_parent_record_scope]"
							enctype="multipart/form-data" method="post"
							onsubmit="return validateAttachment();" target="upload_target"
							style="display: none;">
							<j:if test="${jvar_can_add_attachments}">
								<script>$('sys_attachment').style.display = 'block';</script>
							</j:if>
							<input name="attachments_modified" id="attachments_modified"
								type="hidden" value="" />
							<input name="sysparm_sys_id" type="hidden" value="${jvar_target_sys_id}" />
							<input name="sysparm_table" type="hidden" value="${jvar_target_table}" />
							<input name="u_access_type" type="hidden" value="${accessType}" />
							<input name="max_size" type="hidden" value="${gs.getProperty('com.glide.attachment.max_size')}" />
							<input name="file_types" type="hidden" value="${gs.getProperty('glide.attachment.extensions')}" />
							<input name="sysparm_nostack" type="hidden" value="yes" />
							<input name="sysparm_redirect" type="hidden"
								value="attachment_uploaded.do?sysparm_domain_restore=false&amp;sysparm_nostack=yes" />
							<input id="sysparm_encryption_context" name="sysparm_encryption_context"
								type="hidden" value="" />
							<table style="width: 100%">
								<tr>
									<td>
										<label style="color: black; font-size: 15px; float:left;">Company:</label>
										<g:evaluate var="jvar_qry" object="true">
											var qry= new GlideRecord('company_profile');
											qry.addQuery('sys_id',companyID);
											qry.setLimit(1);
											qry.query();
										<!-- 	console.log("company:"+ qry.getRowCount()); -->
										</g:evaluate>
										<j:if test='${!qry.hasNext()}'>
											<input type="text" id="u_company" class="no-outline" readonly="readonly" value="" style="color: black; font-size: 15px; background-color: white;"/>
										</j:if>
										<j:if test='${qry.next()}'>
											<input type="text" id="u_company" class="no-outline" readonly="readonly" value="${qry.name}" style="color: black; font-size: 15px; padding-left: 30px; background-color: white; float: left"/>
										</j:if>
									</td>
									<td>
										<!--<a id="report" style="font-size: 15px; float: right; display:none" href="javascript&colon;downloadReport()"><u>Download Report</u></a>-->
										<a id="report" style="font-size: 15px; float: right; display:none" ><u>Download Report</u></a>
									</td>
								</tr>
								<tr>
									<td>
										<label style="color: black; font-size: 15px; float:left;">Engagement:</label>
										<g:evaluate var="jvar_qry" object="true">
											var qry= new GlideRecord('engagement');
											qry.addQuery('sys_id',engagementID);
											<!-- qry.setLimit(1); -->
											qry.query();
											<!-- console.log("Engagement:"+ qry.getRowCount()); -->
										</g:evaluate>
										<j:if test='${!qry.hasNext()}'>
											<input type="text" id="u_engagement" class="no-outline" readonly="readonly" value="" style="color: black; font-size: 15px; padding: 10px; background-color: white; float: left"/>
										</j:if>
										<j:if test='${qry.next()}'>
											<input type="text" id="u_engagement" class="no-outline" readonly="readonly" value="${qry.name}" style="color:black; font-size: 15px; padding-left: 10px; background-color: white; float: left"/>
										</j:if>
									</td>
								</tr>
								<tr>
									<td>
										<input type="hidden" readonly="readonly" id="u_practice_type" name="u_practice_type" value="${pracType}"/>
									</td>
									<td>
										<input type="hidden" readonly="readonly" id="u_result_str" name="u_result_str"/>
									</td>
								</tr>
							</table>
							<table id="attachmentTable" width="100%" style="table-layout:fixed;" role="presentation">
								<TR class="attachmentRow">
									<g2:set_if var="jvar_td_styles" test="$[GlideMobileExtensions.getDeviceType() == 'm']" true="visibility: hidden; width: 0;" false=""/>
									<td style="$[jvar_td_styles]" id="attachFileCell" colspan="3">
										<p>
										<input id="attachFile"
											name="attachFile" onChange="checkAndSetAttachButton(); setDeleteButton(this.value); $('attachButton').click();" size="41"
											type="file" style="width: 0.1px;height: 0.1px;opacity: 0;overflow: hidden;position: absolute;z-index: -1;" tabindex="-1">
										<input type="button" title="${gs.getMessage('Attach')}" id="loadFileXml" value="${gs.getMessage('file_attach')}" onclick="document.getElementById('attachFile').click();"/></input>
										<span id="attachFileName" style="color: black; font-size:13px; padding-left: 5px;">No File Chosen</span>
										</p>

										<a href="#" class="attachfile-delete" onclick="clearAttachmentField($(this).up().up()); setDeleteButton(this.value);" style="cursor: default;display:none;">
											<img src="images/icons/kb_no_disabled.gif" />
										</a>
										<input style="display:none;" disabled="true" class="attachfile-attach button" id="attachButton" type="submit"
											value="${gs.getMessage('Attach')}" />
									</td>

									<script>document.getElementById("loadFileXml").focus()</script>

									<j2:if test="$[GlideMobileExtensions.getDeviceType() == 'm']">
										<g:requires name="scripts/snm/cabrillo/js_includes_cabrillo.js" includes="true" />

										<td colspan="3">
											<button id="cabrilloAttach" title="${gs.getMessage('Attach')}" size="41">${gs.getMessage('Attach')}</button>
											<script>
											(function($, cabrillo){
												var cabrilloTable = '${JS:jvar_target_table}';
												var cabrilloSysId = '${JS:jvar_target_sys_id}';
												$('#cabrilloAttach').on('click', function saveCabrilloAttachments(event) {
													event.preventDefault();
													cabrillo.attachments.addFile(cabrilloTable, cabrilloSysId).then(
														function(data) {
															var url = $('[name=sysparm_redirect]').val();
															url += "${AMP}sysparm_name=" + data.sys_id;
															$('#upload_target').attr('src', url);
															validateAttachment();
														},
														function(err) {
															console.error("Upload failed", error);
														}
													);
												});
											})(jQuery, snmCabrillo);
											</script>

										</td>
									</j2:if>
								</TR>
								<j:if test="${jvar_kmfcleprop != 'opt_in'}">
									<g2:attachment_encrypt />
								</j:if>
								
								<TR>
									<td>
										<input style="display:none;" type="button" value="${gs.getMessage('Add Another Attachment')}"
											onclick="addRowToTable()" class="button"></input>
									</td>
								</TR>
							</table>
							
							
						</FORM>
					</td>
				</tr>
			</j:if>
			<j:if test="${jvar_cloudedge_invalid}">
				<tr>
					<td>
						<div class="caption">
							<p>${gs.getMessage('The attachments are encrypted and all actions are disabled until you connect to your company network.')}</p>
						</div>
					</td>
				</tr>
			</j:if>
			<tr>
				<td>
					<img style="margin: 6px 3px 6px 3px;display:none;" id="please_wait"
						 src="images/please_wait.gifx" alt="${gs.getMessage('Please Wait')}" />
					<div class="caption" style="display:none;">
						<span>${gs.getMessage('Current file attachments')}:</span>
					</div>
					<input type="button" value="Cancel" onclick="closeAttachmentWindow()" class="btn btn-primary navbar-btn" style="float:right;"/>
				</td>
			</tr>
			<tr>
				<td>
					<FORM action="sys_attachment.do?DELETE" method="post" target="upload_target"
						onsubmit="return startRemoveAttachments()">
						<input name="sysparm_nostack" type="hidden" value="yes" />
						<input name="sysparm_this_url" id="sysparm_this_url" type="hidden"
							value="" />
						<input name="deleted_sys_ids" id="deleted_sys_ids" type="hidden"
							value="" />
					</FORM>
					<j2:if test="$[jvar_some_deletable]">
						<script>
							document.getElementById('delete_button_span').style.display
							= "none";
						</script>
					</j2:if>
				</td>
			</tr>
		</tbody>
	</table>
	<!-- this is where we send our form submissions so that the dialog stays
		up -->
	<iframe id="upload_target" tabindex="-1" name="upload_target" title="${gs.getMessage('Attachments')}" src="blank.do?sysparm_domain_restore=false"
		style="position:fixed;clip: rect(0,0,0,0);width:100%;height:0;border:0px solid #fff;">$[SP]</iframe>
</j:jelly>

 

 

 

5 REPLIES 5

Rakesh50
Mega Sage

@all anyone ?

Rakesh50
Mega Sage

@Jaspal Singh  @Ankur Bawiskar  @Chuck Tomasi 
Please anyone can look into this ?

@Rakesh50 

things to check

1) is it getting called fine?

2) the way you call it from scoped app in GlideDialogWindow is different than global one

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks for the reply @Ankur Bawiskar ,

 

Yes, the way of calling in ui page is different. I have used below syntax for calling ui page and it is working. I'm able to see the  pop-up of this ui page. but the fields are not coming. After inspecting the pop-up i can see below message and in debug i can see the below error screenshot

var edgeEncryptionEnabledForAttachments = 'null'; 

var dialog=new GlideModal('x_custom_scope_bulk_upload_ui');

Rakesh50_0-1704181305452.png