How to set dateTime & choice value in UI page

Suman Kumari
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.

 

@Ankur Bawiskar @Runjay Patel @Brad Bowman  

1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

Hi @Suman Kumari ,

 

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

6 REPLIES 6

Shaqeel
Mega Sage

Hi @Suman Kumari 

 

Here is the article I found that might help you:

Solved: Set choice list value from a UI Page - ServiceNow Community

 

Regards

Shaqeel


***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

***********************************************************************************************************************





Regards

Shaqeel

Ankur Bawiskar
Tera Patron
Tera Patron

@Suman Kumari 

seems issue with the date/time format the way how it's displayed on form and within html

Did you check that?

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Suman Kumari 

try this

var gdw = new GlideDialogWindow('ui page');
        gdw.setSize(750, 300);
        gdw.setPreference('sysId', g_form.getUniqueValue());
        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

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


<g:evaluate jelly="true" var="jvar_date">
    var sysId = jelly.jvar_sysId;
var rec = new GlideRecord('tableName');
rec.get(sysId);
    var val = rec.xyz.getDisplayValue();
val;
</g:evaluate>

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

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

Thanks for the reply.

doing the same for date and time, there was a syntax error, got resolve now.

 

but i am not able  to set the choice value dynamically which i am passing from client side.