submit dailog ok and cancel buttons not working

harivas
Tera Contributor

I have a query when I hit on the dailog 'OK' do the processing CANCEL' do not process the buttons are not working I have written the below script in UI page
HTML:

<?xml version="1.0" encoding="UTF-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:g="glide">
  <g:ui_form>
    <g:evaluate jelly="true">
      var task = jelly.sysparm_sys_id;
    </g:evaluate>

    <div class="form-horizontal">
      <div class="form-group is-required" id="dateSelector">
        <div class="modal-row">
          <label class="col-sm-12 col-md-4 control-label form-field-height" for="end_date">
            <span class="required-marker label_description"></span>
            <span class="label-text">${gs.getMessage('Resource plan end date')}</span>
          </label>
          <div class="form-field col-sm-12 col-md-5 input_controls">
            <!-- Populate the g:ui_date field with the current date -->
            <g:ui_date name="end_date" id="end_date"/>
            <p class="help-block" id="endDateError" role="alert"></p>
            <p class="help-block" id="rangeError" role="alert"></p>
          </div>
        </div>
        <input type="hidden" name="task" id="task" value="${sysparm_sys_id}"/>
        <input type="hidden" id="cancelled" name="cancelled" value="false"/>
        <input type="hidden" id="submitted" name="submitted" value="false"/>
      </div>
      <div class="pull-right form-group" id="dialog-btns">
        <g:dialog_buttons_ok_cancel ok="return submitDialog()" cancel="return cancelDialog()"/>
      </div>                                  
    </div>
  </g:ui_form>
  <script>
    // Get today's date
    var today = new Date();
    var dd = String(today.getDate()).padStart(2, '0');
    var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
    var yyyy = today.getFullYear();

    today = yyyy + '-' + mm + '-' + dd;

    // Set the date field value
    document.getElementById('end_date').value = today;
  </script>
</j:jelly>

Processing script:
 
function submitDialog() {
    // var Rp = new GlideRecord('pm_project');
    // Rp.get(task);
    //gs.log(task);
    var gr = new GlideRecord('resource_plan');
    gr.addQuery('task', Rp.sys_id);
    gr.addEncodedQuery('stateIN2,1,11,3');
    gr.query();

    while (gr.next()) {
        if (gr.state == '11' || gr.state == '3') {
            gr.state = '7';
        } else {
            gr.state = '8';
        }
        gr.update();
    }
// Return true to close the dialog
    return true;
}

function cancelDialog() {
    // No action needed when the Cancel button is clicked
    return true;
}
var urlOnStack = GlideSession.get().getStack().bottom();
response.sendRedirect(urlOnStack);

when the code is out side of the functions its working for both 'OK' and 'CANCEL' buttons, How can I resolve this.

And also, which date on Dailog window field date value I need to set in resource plan end date field How can I get this this Value 
attaching screen shots for your reference

Thanks
Harivas G


2 REPLIES 2

Jake Sadler
Kilo Sage

Hi @harivas 

 

The functions need to be in the client script and return true or false.

 

When true is returned the processing script will run.

When false is returned then it will do nothing.

 

Client script:

function cancelDialog() {
    // No action needed when the Cancel button is clicked
    return false;
}
 
function submitDialog() {
    // run processing script
    return true;
}
 
processing script:
 
  // var Rp = new GlideRecord('pm_project');
    // Rp.get(task);
    //gs.log(task);
    var gr = new GlideRecord('resource_plan');
    gr.addQuery('task'Rp.sys_id);
    gr.addEncodedQuery('stateIN2,1,11,3');
    gr.query();

    while (gr.next()) {
        if (gr.state == '11' || gr.state == '3') {
            gr.state = '7';
        } else {
            gr.state = '8';
        }
        gr.update();
    }
 
var urlOnStack = GlideSession.get().getStack().bottom();
response.sendRedirect(urlOnStack);



Hello @Jake Sadler,

thanks for your reply.

when hit on cancel button no actions performed, but dailog box displaying how can we close that dailog box & How dailog field date value set into the resource plan records end_date field.