how to parse the html input variable into jelly evaluate

shekar038
Kilo Contributor

I pasted piece of   HTML UI page script below. My requirement to dyanmically change the Due date(project_due_date) according to months selected . The due date should to be equal to current + months(selection). I am trying to perform this basic calculation using g:evaluate and assign the result   jvar_ variable to date field.

But I am having difficulty in parsing the number months (due_months) selected into the jelly evaluate.

Also if you can help in changing date field as display only woudld be great full   .i have tried many option like disabled="disabled" .Noting seems to work.Jelly is wierd and crazy to work with.

any help is highly appreciated.

<tr id="description_row" valign="top">

                              <td>

                                      Due date

                              </td>

  <td>

                      <span class="mandatory" width="2px">&amp;amp;nbsp;</span>

                      <select   name="due_months" id="due_months" >

                                              <option value="0">Select</option>

                                              <option value="3">3 months</option>

                                              <option value="6">6 months</option>

                                              <option value="12">1 year</option>    

                      </select>

<g:evaluate var ="jvar_due_date" objects="true" jelly ="true">

                  var today = new GlideDateTime();

                            today =gs.nowDateTime();

                            today.addMonths(${due_months});

</g:evaluate>

                                      <span width="2px">&amp;amp;nbsp;</span>

                                      <g:ui_date id="project_due_date" name="project_due_date" value="$[jvar_due_date]"   />

                              </td>

                      </tr>

8 REPLIES 8

Alex North
ServiceNow Employee

Honestly, I'm not certain. The method which Abhinay has provided will certainly fire the logic each time the drop down is changed.


Here is your html



<tr id="description_row" valign="top">


                              <td>


                                      Due date


                              </td>


  <td>


                      <span class="mandatory" width="2px">&amp;amp;nbsp;</span>



                      <select   name="due_months" id="due_months" onchange="myFunction()">


                                              <option value="0">Select</option>


                                              <option value="3">3 months</option>


                                              <option value="6">6 months</option>


                                              <option value="12">1 year</option>  


                      </select>



                                      <span width="2px">&amp;amp;nbsp;</span>


                                      <g:ui_date id="project_due_date" name="project_due_date" value=""   />


                              </td>


                      </tr>



Client script:


function myFunction(){


  var months= parseInt($('due_months').value);


  var ga = new GlideAjax('DateUtil');


  ga.addParam('sysparm_name','getDate');


  ga.addParam('sysparm_months',months);


  ga.getXML(callBack);



  function callBack(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  $('project_due_date').value=answer;


  }



}



Script include:


var DateUtil = Class.create();


DateUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  getDate: function(){


  var gdt= new GlideDateTime(gs.nowDateTime());


  gdt.addMonthsLocalTime(parseInt(this.getParameter('sysparm_months')));


  var gd= new GlideDate();


  gd.setValue(gdt.getDate());


  return gd.getByFormat("MM-dd-yyyy");


  },


  type: 'DateUtil'


});


Thanks Abhinay for your response. I am trying to make minimal modification for existing code. Your code will definitely help me in better understanding parsing variable   and date time calculation thank you.


I don't think you can get select box value directly in your html. you need to use a client script to get the value and then use GlideAjax to set the value.