How to set date and time and choice value in ui page

Suman7
Tera Contributor

i am passing value from client side to ui page like below.

 

 

var gdw = new GlideDialogWindow('ui page');
        gdw.setSize(750, 300);
        
        gdw.setPreference('abc',g_form.getValue('abc')); // abc is choice value
        gdw.setPreference('xyz',g_form.getValue('xyz'));	// xyz is datetime value
        gdw.render();

 

 

Ui Page code

 

<select id="xyz" name="xyz" >
  <g:options choiceList="${choiceList}"  />
</select> 

<g:evaluate var="abc"  expression="RP.getWindowProperties().abc"/>

<g:ui_date_time name="DateTime" field='abc' value="${abc}"/> 

 

 

Date is not populating but when i tried with gs.getDateTime() then its working withn current date.

1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

Hi @Suman7 ,

 

To set the choice list use code like below. You can take reference from OOB ui page "edit_link_popup".

 

<g:evaluate>
      var relTypes = new GlideRecord('cmdb_rel_type'); // replace with your table
      relTypes.orderBy('parent_descriptor');
      relTypes.query();
    </g:evaluate>



<select id='select_relationship_type'>
         <j:while test="${relTypes.next()}">
            <j:choose>
              <j:when test="${relTypes.sys_id==${RP.getWindowProperties().get('xyz')}}">
                 <option value="${relTypes.sys_id}" selected="selected">${relTypes.name}</option> // replace with your field name
              </j:when>
              <j:otherwise>
                 <option value="${relTypes.sys_id}">${relTypes.name}</option>
              </j:otherwise>
            </j:choose>
         </j:while>
         </select>

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Suman7 

Seems a duplicate question. I answered it here

How to set dateTime & choice value in UI page 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Runjay Patel
Giga Sage

Hi @Suman7 ,

 

To set the choice list use code like below. You can take reference from OOB ui page "edit_link_popup".

 

<g:evaluate>
      var relTypes = new GlideRecord('cmdb_rel_type'); // replace with your table
      relTypes.orderBy('parent_descriptor');
      relTypes.query();
    </g:evaluate>



<select id='select_relationship_type'>
         <j:while test="${relTypes.next()}">
            <j:choose>
              <j:when test="${relTypes.sys_id==${RP.getWindowProperties().get('xyz')}}">
                 <option value="${relTypes.sys_id}" selected="selected">${relTypes.name}</option> // replace with your field name
              </j:when>
              <j:otherwise>
                 <option value="${relTypes.sys_id}">${relTypes.name}</option>
              </j:otherwise>
            </j:choose>
         </j:while>
         </select>

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Suman7
Tera Contributor

Thankyou @Runjay Patel.