Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to set default value on UI Page Dropdown

JRY
Mega Guru

Hello,

I'm trying to set default value based on Order specification on dropdown which I have created using UI Page and it's not redirecting to current page it's staying on UI page.

Can anyone help me what needs to change in below Script

HTML Script 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g:ui_form>
<g:evaluate var="jvar_sysid"
expression="RP.getWindowProperties().get('sysid')"/>
<table width="320px">
<tr>
<g:evaluate var="jvar_sysid" jelly = "true">
var tinaSpecification = jelly.jvar_u_order_specification;
var extOrder = new GlideRecord("u_task_order");
extOrder.addQuery("sys_id", jelly.jvar_sysid);
extOrder.query();
extOrder.next();
extOrder;
</g:evaluate>
<input type="hidden" id="hidden" value="jvar_id"/>
<td width="50%">
<div class="col-md-7">

<j:if test="${jvar_u_order_specification =='5f2eae2db0a19010c77c76087d5096e5'}">
<g:ui_reference name="u_order_specification" value="${jvar_u_order_specification}" displayvalue="/29" table="u_task_order" query="active=true^u_order_specification=5f2eae2db0a19010c77c76087d5096e5"/>
</j:if>

<j:if test="${jvar_u_order_specification =='eaf915864d6d1010c77c99e6422b6e38'}">
<g:ui_reference name="u_order_specification" value="${jvar_u_order_specification}" displayvalue="/28" table="u_task_order" query="active=true^u_order_specification=eaf915864d6d1010c77c99e6422b6e38"/>
</j:if>
</div>
</td>

<td align="center">

<select id="subnet_mask" name="Subnet Mask">
<option value="" selected="selected">-- None --</option>
<option value = "/26" >/26</option>
<option value = "/27" >/27</option>
<option value = "/28" >/28</option>
<option value = "/29" >/29</option>
</select>
</td>
</tr>
</table>

<table width="100%">
<tr id="dialog_buttons">
<td colspan="2" align="left">
<td colspan="2" style="text-align:center;padding-top:10px;">
<input type="hidden" id="task_sys_id" name="task_sys_id" value="${jvar_sysid}"/>
<button class="btn btn-default" onclick="continueCancel()" style="margin-right:10px;">Cancel</button>
<button class="btn btn-primary" onclick="continueOK()">Ok</button>

</td>
</td>
</tr>
</table>
</g:ui_form>

</j:jelly>

 

Client Script 

//If OK Button is pressed then this functionis called as defined in HTML Line Number 22
function continueOK() {
var ipChoices = gel('subnet_mask').value;
g_form.setValue('subnet_mask', ipChoices);
g_form.save();
g_form.addInfoMessage(task_sys_id);
return true;
}
//If Cancel is pressed then this functionis called as defined in HTML Line Number 21
function continueCancel() {
GlideDialogWindow.get().destroy();
}

 

Processing Script

gs.log('reserve_lan_ip UI Page' + task_sys_id);

var grCFS = new GlideRecord('u_task_mega_pop_l3_cfs_order');
grCFS.get(task_sys_id);

var scReseverLanIP = new TN_ValidateBusinessParameters_ReserveLANIP.process(grCFS, subnet_mask);
var urlOnStack = gs.getUrlOnStack();
response.sendRedirect(urlOnStack);
response.sendRedirect(task_table_name + ".do?sys_id=" + task_sys_id);

 

Thanks,

JRY

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

to set default value you can do this

you are already doing this for None

<select id="subnet_mask" name="Subnet Mask">
<option value="" selected="selected">-- None --</option>
<option value = "/26" selected="selected">/26</option>
<option value = "/27" >/27</option>
<option value = "/28" >/28</option>
<option value = "/29" >/29</option>
</select>

where do you wish UI page to redirect?

update as this and test

gs.log('reserve_lan_ip UI Page' + task_sys_id);

var grCFS = new GlideRecord('u_task_mega_pop_l3_cfs_order');
grCFS.get(task_sys_id);

var scReseverLanIP = new TN_ValidateBusinessParameters_ReserveLANIP.process(grCFS, subnet_mask);
var urlOnStack = gs.getUrlOnStack();
//response.sendRedirect(urlOnStack); // comment this
response.sendRedirect('u_task_mega_pop_l3_cfs_order' + ".do?sys_id=" + task_sys_id);

Regards
Ankur

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

to set default value you can do this

you are already doing this for None

<select id="subnet_mask" name="Subnet Mask">
<option value="" selected="selected">-- None --</option>
<option value = "/26" selected="selected">/26</option>
<option value = "/27" >/27</option>
<option value = "/28" >/28</option>
<option value = "/29" >/29</option>
</select>

where do you wish UI page to redirect?

update as this and test

gs.log('reserve_lan_ip UI Page' + task_sys_id);

var grCFS = new GlideRecord('u_task_mega_pop_l3_cfs_order');
grCFS.get(task_sys_id);

var scReseverLanIP = new TN_ValidateBusinessParameters_ReserveLANIP.process(grCFS, subnet_mask);
var urlOnStack = gs.getUrlOnStack();
//response.sendRedirect(urlOnStack); // comment this
response.sendRedirect('u_task_mega_pop_l3_cfs_order' + ".do?sys_id=" + task_sys_id);

Regards
Ankur

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

Hi Ankur,

Thanks for reply, but here I need to set default value based on Reference field on the form.

 

Thanks,

JRY

Hi,

you want to set drop down value based on g:ui_reference?

Regards
Ankur

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