Set value of a condition field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2013 07:17 AM
Hi,
i need help with setting a condition field (you know: the filter condition field that depends on a collection field).
I am implementing new application where I have a new ticket type and have a kind of template with a condition field (name: u_condition; type: condition: depends on: u_collection).
I am able to read the value of that filed by default g_form.getValue('u_condition').
But it is not possible to set the value of the other condition field by g_form.setValue('u_condition', '=', condition)
My script is:
function setConditionFromConditionTample() { var template = g_form.getReference('u_filter_template'); if(template !== null) { if(g_form.getValue('u_table') == template.u_collection) { alert(template.u_condition); // alert: active=true^EQ g_form.setValue('u_condition_string', template.u_condition); // nothing happen here return true; } else { alert('Selected template has to match with filter table. Select another template or contact your administrator, please.'); } } else { alert('Filter template could not be loaded. Please contact your administrator.'); } return false; }
***********
the variable
template.u_conditiondoes have the value like
active=true^EQ. But the condition field doest updated.
Any expirience with that?
Kind regards
Konstantin
Cheers,
Kostya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2013 06:14 AM
For information,
the server side function setValue is working fine for condition field. F.e.
var gr = new GlideRecord('u_cn_customer_notification');
if(gr.get('04ebfddaec9b7440c34881651fb5c145')) {
gr.setValue('u_condition', 'active=false');
gr.update();
}
is working as expected. So i think it is a problem with g_form API
Cheers,
Kostya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2015 04:29 PM
KonstantinThank you! Thank you! Thank you! This has helped me in another scenario that I was trying very hard to make it work!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2022 11:10 PM
Hi @Kostya
g_form.getReference() function takes 2 parameters. Refer below link for that and search for it:
Please find updated code below:
function setConditionFromConditionTample() {
var template = g_form.getReference('u_filter_template', filterTemplate);
}
function filterTemplate(template) {
if(template !== null) {
if(g_form.getValue('u_table') == template.u_collection) {
alert(template.u_condition); // alert: active=true^EQ
g_form.setValue('u_condition_string', template.u_condition);
//return true;
} else {
alert('Selected template has to match with filter table. Select another template or contact your administrator, please.');
}
} else {
alert('Filter template could not be loaded. Please contact your administrator.');
}
// return false;
}
Commented return for now but if required based on your requirement, you can use it on your code and try.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2023 02:59 AM
Hello,
I have the same problem but I get an error that the sys ID is not valid in the condition.
What could be me wrong with this code? I want to set a condition that filters the Fix Available is true.
(function(outputs, steps, stepResult, assertEqual) {
var gr = new GlideRecord("sn_vul_action_select_vi");
if (gr.get(steps('27a02cb7973c7590481abce3f153qwe1').first_record) ){
gr.setValue('condition', 'fix_available=true');
gr.update();
}
})(outputs, steps, stepResult, assertEqual);