Create a modal with a select box

jkelvynsant
Tera Contributor

Hello, is it possible to create a modal in the portal that includes a select box, to be displayed when a request is rejected?

I tried to create one, but it only accepts text.

 

jkelvynsant_0-1793738873369.png

 

3 REPLIES 3

kmohammed
Tera Guru

Hi, yes this is possible - but not with spModal.prompt(), confirm() or alert(). Those built-in variants only support text input or buttons, which is why your modal only accepts text.

 

You need a modal that renders a small custom widget, so the select lives in that widget:

 

1. Create a tiny widget, e.g. Reject Reason, whose body is just a select bound to a model, for example: <select class="form-control" ng-model="c.data.reason" ng-options="o.value as o.label for o in c.data.options"></select> - populate c.data.options in its server script or pass them in as widget input.

2. In the client controller of the widget that shows the Reject button, open it with spModal.open({ title: 'Reject Request', widget: 'reject-reason', widgetInput: { options: [...] }, buttons: [{ label: 'Cancel', cancel: true }, { label: 'Reject Request', primary: true }] }). The promise resolves with the embedded widget's scope/data when the primary button is clicked, so you can read the chosen value from the result instead of free text.

3. Use that returned value in your existing reject logic - update the record state to Rejected and write the selected reason to work notes/comments (or a dedicated rejection reason field if you have one) via your server-side call / GlideRecord update, exactly as you do today with the text.

 

Two small points that match your screenshot: keep the primary/Reject button disabled (or validate on submit) until a reason is actually selected, so an approver cannot reject with an empty reason; and if the same reason list is needed in the platform UI as well, drive the options from a choice list / table rather than hard-coding them in the widget, so both places stay in sync.

Aditya_hublikar
Giga Sage

Hello @jkelvynsant ,

 

Could you more elaborate about your requirement ? So it will help to resolve .

 

 

yashkamde
Tera Sage

Hello @jkelvynsant ,

 

Yes to get a custom dropdown menu inside a modal without it being stripped out by ServiceNow's spModal layout engine, one way is to put the modal HTML directly inside your HTML Template and control its visibility with a simple boolean flag in the Client Script.

Screenshot 2026-11-04 120717.png

 

Below you can refer the widget code :

HTML :

<div class="panel panel-default b">
  <div class="panel-body text-center">
    <h3>Testar Rejeição de Solicitação</h3>
    <p>Clique no botão abaixo para simular a ação de rejeição e visualizar o modal.</p>
    
    <!-- Button triggers the client-side controller function to open the modal -->
    <button type="button" class="btn btn-danger btn-lg" ng-click="c.openRejectModal()">
      Rejeitar Solicitação
    </button>
  </div>
</div>

<!-- Custom Rejection Modal Layout Overlay -->
<div class="modal fade in" tabindex="-1" role="dialog" style="display: block;" ng-if="c.showModal">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      
      <!-- Modal Header -->
      <div class="modal-header">
        <button type="button" class="close" ng-click="c.closeRejectModal()">&times;</button>
        <h4 class="modal-title">Rejeitar Solicitação</h4>
      </div>
      
      <!-- Modal Body -->
      <div class="modal-body">
        <p>Por favor, selecione o motivo da rejeição:</p>
        <div class="form-group">
          <select class="form-control" ng-model="c.selectedReason">
            <option value="" disabled selected>Selecione um motivo...</option>
            <option value="missing_docs">Documentação incompleta</option>
            <option value="wrong_format">Formato incorreto</option>
            <option value="duplicate">Solicitação duplicada</option>
            <option value="other">Outro motivo</option>
          </select>
        </div>
      </div>
      
      <!-- Modal Footer Action Buttons -->
      <div class="modal-footer">
        <button type="button" class="btn btn-default" ng-click="c.closeRejectModal()">Cancelar</button>
        <button type="button" class="btn btn-primary" ng-disabled="!c.selectedReason" ng-click="c.submitRejection()">
          Rejeitar Solicitação
        </button>
      </div>
      
    </div>
  </div>
</div>

<!-- Background backdrop dark overlay when modal is active -->
<div class="modal-backdrop fade in" ng-if="c.showModal"></div>

 

Client Script :

 

api.controller = function() {
    /* widget controller */
    var c = this;
    
    // Controlled via boolean flags instead of spModal
    c.showModal = false;
    c.selectedReason = '';

    // Opens the HTML modal
    c.openRejectModal = function() {
        c.selectedReason = ''; 
        c.showModal = true;
    };

    // Closes the HTML modal
    c.closeRejectModal = function() {
        c.showModal = false;
    };

    // Submits the reason to the Server Script
    c.submitRejection = function() {
        if (c.selectedReason) {
            c.data.action = "rejectRequest";
            c.data.reason = c.selectedReason;
            
            c.server.update().then(function(response) {
                c.showModal = false; 
                alert('Solicitação rejeitada com sucesso!');
            });
        }
    };
};

 

Server Script :

 

(function() {
    /* populate the 'data' object */
    
    // Check if the user confirmed a rejection action from the modal interface
    if (input && input.action === "rejectRequest") {
        var selectedReasonValue = input.reason;
        
        // Logs transaction profile data directly into the system log environment
        gs.info("Request rejected via portal modal. Selected reason value: " + selectedReasonValue);
    }
})();

 

If my response helped mark as helpful and accept the solution.