Client Script to set value true if field from another is true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2016 07:20 AM
Need help with a client script to set a field true, if a field on another table related to a change request is true. Looking at the Affected CI's to see if Tagged for DR is true.
What I need is:
If "u_tagged_dr" is true on the "task_ci" table and matches the sysid of the Change Request
Set value of field "u_core_or_critical_ci_affected" to true
Here is what I have so far and it is not working
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var cc = new GlideRecord('task_ci');
cc.addQuery('task_ci', g_form.getValue('u_tagged_dr', true));
cc.query();
if (cc.next()) {
g_form.setValue('u_core_or_critical_ci_affected', 'true');
}
}
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2016 07:24 AM
Will add I want to try this as a Client Script and not a Business Rule for a certain reason. Currently we have two business rules which work off each other and they are working. BR #1 sets field "u_core_or_critical_ci_affected" to true, and BR #2 checks risks conditions which one of those conditions is if "u_core_or_critical_ci_affected" is set to true. It requires two updates of a record to match the condition and modify the risk, my thought is a Client Script will update the field before the Risk Condition check occurs and only require a single update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2016 07:24 AM
This should do it, query for a record linked to the current task and with u_tagged_dr as true and if you find one, set the value on the form and return;
ideally when doing server side gliderecords you should be using glideAjax though to keep form loads and slowness down to a minimum:
http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var cc = new GlideRecord('task_ci');
cc.addQuery('task', g_form.getUniqueValue());
cc.addQuery('u_tagged_dr',true);
cc.query();
if (cc.next()) {
g_form.setValue('u_core_or_critical_ci_affected', 'true');
return;
}
}
Also do you need this onChange of a field or onLoad?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2016 07:27 AM
Also do you need this onChange of a field or onLoad? I don't know, I just want it to set the value as soon as it becomes true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2016 07:27 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var cc = new GlideRecord('task_ci');
cc.addQuery('sy_id', 'sys_id of change request');
cc.query();
if (cc.next()) {
g_form.setValue('u_core_or_critical_ci_affected', cc.u_tagged_dr);
}
}