The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Client Script to set value true if field from another is true

taddparris
Kilo Expert

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,

11 REPLIES 11

taddparris
Kilo Expert

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.


marcguy
ServiceNow Employee
ServiceNow Employee

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?


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.


fkhan
Kilo Guru

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);


        }


}