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 condition builder?

arjun_basnet
Giga Contributor

Hi,

I am trying to use ServiceNow Condition builder on UI page,

Condition Builder   this thread helped me to achieve that but problem is, is it possible to set condition builder using encoded query? It's good that we can get encoded query by script. I have tried too many option but without luck.

6 REPLIES 6

brian_degroot
ServiceNow Employee
ServiceNow Employee

Hi Arjun,



You can set the value of a condition field using the query you want ran. To find the correct syntax, what you can do is input the parameters as you normally would, save the record, then right-click the form header and Show XML. You should see the query string for the field here that you can use in your script.



For example, entering State - is - Active will show "state=2^EQ"



Thank you,



Brian


Hi Brian,



I think I haven't been able to explain my problem. I was trying to create a condition builder on UI page



I followed these steps to create UI elemetns for condition builder on UI page



1. Create the condition/table field as you normally would on the table of your choice.
2. Write down the sys_id of the Dictionary record of those items.
3. create your UI page.
4. use the following jelly tags:




  1. <g:ui_element table="[table_name]" field="[table_reference_field]" id="[sys_id_in_dictionary]"></g:ui_element>  
  2. <g:ui_element table="[table_name]" field="[condition_field[" id="[sys_id_in_dictionary]"></g:ui_element>  



5. replace the items within the [ ] tags.


6. Try your UI page.



I can get the encoded query from this newly created condition builder using getFilter() method, but isn't there any method where I specify condition builder id and encoded query and then it sets that particular condition builder with those values.



I looked into ServiceNow scripts, I belive GlideFilter14.js is the own which builds condition builder, I tried different methods looking at this script to create my own condition builder UI but it simply didn't work.



ServiceNow should have some method to set condition builder, when a form for record with condition values gets loaded.



I don't know weather you understood my question or not, but I worked out on this by just loading different form view on ui page using iframe honestly I dont like that approach on top mine is angular app so dont have control over what goes inside that iframe.



I would be happy to know if there is a way to have access to GlideFrom, GlideUIElement contructuor method, we just have access to a instance g_form. But can we create our own?


prashantdharne
Tera Contributor

Hi Arjun,



I am trying to build a filter on my UI page as well. Wondering if you could help me understand the below code. What does this code mean? When we say table_reference_field and condition_field, what are those fields??





  1. <g:ui_element table="[table_name]" field="[table_reference_field]" id="[sys_id_in_dictionary]"></g:ui_element>  
  2. <g:ui_element table="[table_name]" field="[condition_field[" id="[sys_id_in_dictionary]"></g:ui_element>

Hi Prashant,



'table_reference_field' means a fileld in the table which contains list of table name e.g. in sys_script table 'collection' field contains list of table name is of type 'Table Name'


'condition_field' means a field in the table which is of type Conditions