We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

Hi Hemashekar,



You will almost certainly want to make sure the due_months variable has been cast as an integer. Out of curiosity, where is your due_months coming from / being set as a variable?



I'm guessing you also want to pass back the "today" value to jvar_due_date - don't forget to pass it back out at the end of the evaluate:



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


                  var today = new GlideDateTime();


                            today =gs.nowDateTime();


                            today.addMonths(parseInt(${due_months}));


                            today


</g:evaluate>



Let me know how you get on!



Alex


Hi Alex,


Thanks for your reply.


due_months will be passed from the drop down selection option just above the evaluate in the html.


<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>


parseInt() does here?



thanks  


Alex North
ServiceNow Employee

Hi Hemashekar,



parseInt() forces javascript to interpret the value you are pulling from the drop down as a number - right now he thinks it's a string. The addMonths function is expecting a numeric value, not a string. Link to API reference



Alex


Thanks Alex for your response. Do you think the will dynamically change the value of the project_start_date every time I select the month option.



Or writing javascript just for this operation is good way??