How to Hide Document type field in servicenow

Mehar Naaz
Tera Contributor

MeharNaaz_0-1687957389069.png

I have a requirement to hide this Table name field only Document field should be visible. 

 

1 ACCEPTED SOLUTION

Arun_S1
Tera Guru
Tera Guru

@Mehar Naaz I have modified the UI Page "document_selector" HTML in such a way that if your table name field is read only the field will not be displayed. Once you mark the field editable it will automatically displayed in the page.

 

<?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 table_name = RP.getWindowProperties().get( 'sysparm_table' );
        var document_key = RP.getWindowProperties().get( 'sysparm_key' );
        var document_display = RP.getWindowProperties().get( 'sysparm_display' );
        var tableChoicesScript = RP.getWindowProperties().get( 'tableChoicesScript' );
        var showAllTables = RP.getWindowProperties().get( 'showAllTables' );
        var tableReadOnly = ('true' == RP.getWindowProperties().get('tableReadOnly'));
        var parent_ref = RP.getWindowProperties().get( 'sysparm_parent_ref' );
  </g:evaluate>
    <input type="hidden" id="initial_table_name" value="${table_name}" />
    <input type="hidden" id="parent_ref" name="parent_ref" value="${parent_ref}" />
    <g:ui_table>
	<div class="form-group">
               
                <j:if test="${tableReadOnly}">
                    <input type="hidden" style="${jvar_add_style}" id="table_name" name="table_name"
                        value="${table_name}" class="form-control disabled" readonly="readonly"/>
                </j:if>
                <j:if test="${!tableReadOnly}">
					 <label for="table_name"> ${gs.getMessage('Table name')}:
                </label>
                    <select id="table_name" name="table_name" class="form-control" onchange="setupReference()">
                        <j:if test="${tableChoicesScript == ''}">
                            <g:table_options selected="${table_name}" all="${showAllTables}"/>
                        </j:if>
                        <j:if test="${tableChoicesScript != ''}">
                            <g:scripted_table_options selected="${table_name}" script="${SAFE:tableChoicesScript}" />
                        </j:if>
                    </select>
                </j:if>
		</div>
		<div class="form-group">
			<label for="${document_key}"> ${gs.getMessage('Document')}: </label>
                <g:ui_reference name="document_key" table="${table_name}" value="${document_key}" displayvalue="${document_display}" />
            </div>
			<div class="modal-footer">
				<span class="pull-right">
	                <g:dialog_buttons_ok_cancel ok="return validateAndSubmit();" />
				</span>
			</div>

    </g:ui_table>

</j:jelly>

 

When the table name field is not read-only.

Arun_S1_0-1688371027201.png

 

When the table name field is read-only

Arun_S1_1-1688371100461.png

 

Please mark the appropriate response as correct answer and helpful.

 

View solution in original post

3 REPLIES 3

NewBiee
Tera Contributor

Hi Mehar,

Can you please share more details about your requirement.

Thanks.

Dependency is a new  form  in which "depends on" is a document id field in this field "Table name" and "Document" field is available. "Table name" should be hidden from selected users only "Document" field should be  shown up.

 

 

Arun_S1
Tera Guru
Tera Guru

@Mehar Naaz I have modified the UI Page "document_selector" HTML in such a way that if your table name field is read only the field will not be displayed. Once you mark the field editable it will automatically displayed in the page.

 

<?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 table_name = RP.getWindowProperties().get( 'sysparm_table' );
        var document_key = RP.getWindowProperties().get( 'sysparm_key' );
        var document_display = RP.getWindowProperties().get( 'sysparm_display' );
        var tableChoicesScript = RP.getWindowProperties().get( 'tableChoicesScript' );
        var showAllTables = RP.getWindowProperties().get( 'showAllTables' );
        var tableReadOnly = ('true' == RP.getWindowProperties().get('tableReadOnly'));
        var parent_ref = RP.getWindowProperties().get( 'sysparm_parent_ref' );
  </g:evaluate>
    <input type="hidden" id="initial_table_name" value="${table_name}" />
    <input type="hidden" id="parent_ref" name="parent_ref" value="${parent_ref}" />
    <g:ui_table>
	<div class="form-group">
               
                <j:if test="${tableReadOnly}">
                    <input type="hidden" style="${jvar_add_style}" id="table_name" name="table_name"
                        value="${table_name}" class="form-control disabled" readonly="readonly"/>
                </j:if>
                <j:if test="${!tableReadOnly}">
					 <label for="table_name"> ${gs.getMessage('Table name')}:
                </label>
                    <select id="table_name" name="table_name" class="form-control" onchange="setupReference()">
                        <j:if test="${tableChoicesScript == ''}">
                            <g:table_options selected="${table_name}" all="${showAllTables}"/>
                        </j:if>
                        <j:if test="${tableChoicesScript != ''}">
                            <g:scripted_table_options selected="${table_name}" script="${SAFE:tableChoicesScript}" />
                        </j:if>
                    </select>
                </j:if>
		</div>
		<div class="form-group">
			<label for="${document_key}"> ${gs.getMessage('Document')}: </label>
                <g:ui_reference name="document_key" table="${table_name}" value="${document_key}" displayvalue="${document_display}" />
            </div>
			<div class="modal-footer">
				<span class="pull-right">
	                <g:dialog_buttons_ok_cancel ok="return validateAndSubmit();" />
				</span>
			</div>

    </g:ui_table>

</j:jelly>

 

When the table name field is not read-only.

Arun_S1_0-1688371027201.png

 

When the table name field is read-only

Arun_S1_1-1688371100461.png

 

Please mark the appropriate response as correct answer and helpful.