Setting ui_choicelist value

fraser_thomson
Kilo Explorer

Hey guys,

 

I'm currently creating a UI page and using <g:ui_choicelist>, the parameters I have are name, table and field.

I was wondering if there was a way to set the value of this choicelist? It always defaults to the first in sequence?

 

Thanks

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi Fraser,



I have a ui page where i did create a dropdown, its the simple HTML code and its working just fine:


<select id="approvers" onchange="test()" style="width:200px">


<option value=''> -- None --   </option>


<option value='a'> A   </option>


<option value='b'> B   </option>


</select>


-Anurag

View solution in original post

17 REPLIES 17

Yeah, sorry I didn't mention that it worked for me too.


The problem is my selected value does indeed need to be dynamic.
With using the above, the issue being that the selected value also becomes a choice on the drop down.
I'll try doing a function using a GR for the field value and then creates options dependent on that.


ok, I hear you. I did something like this a while ago, so what I did was make the option id the same as the option value(makes it easier to keep the id different for each choice while setting the value in a loop), then after the page loaded, I made a function call which checked for certain parameters, then searched the dom id for this particular choice and set the selected value



document.getElementById("<option_id").selected="selected";



I dont remember is exactly, it was something like this. Hope that helps



Regars,


Hari


Thanks Hari.



I did it another way;
I used a choose loop that tested whether or not the field on the record was a certain value and if so, created correct choices and had correct selected values on the choice list.


Kalaiarasan Pus
Giga Sage

not sure if this is what you are looking for ...



created a simple page with ui_choicelist...



https://demo001.service-now.com/sys_ui_page.do?sys_id=e604d79f58003100eb794fb7ffc2d6a4&sysparm_view=



it seems like you need to set some value dynamically in the choice list... you could use the 'onLoadFunction' function on the UI page and set the value as required by adding your logic (maybe a glideajax)....


pasting the code here....



HTML



<?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_choicelist name="myquantity" table="sc_cart_item" field="quantity" />



<script>


addLoadEvent( function() {


onLoadFunction();


});


</script>


</j:jelly>



----------



Client script




function onLoadFunction()


{


      document.getElementById("myquantity").value = '2';


}