"Missing semicolon" compile error on a script

arnoldzwane
Kilo Contributor

I am getting a "Missing semicolon" compile error on line 10 "If (gen.u_gen_cpu_name == ci.cpu_name){" of my script below: 

//get CIs
var ci = new GlideRecord('cmdb_ci_computer');
ci.query();
while (ci.next()) {
   //get the Generation record for this CI (only one record)
   var gen = new GlideRecord("u_cpu_generation");
   gen.addQuery("ci",ci.sys_id.toString());
   gen.query();
   while (gen.next()){
      If (gen.u_gen_cpu_name == ci.cpu_name){
         ci.u_cpu_generation = gen.u_gen_cpu_generation;
         ci.u_processor_windows_10_capable = gen.u_processor_windows_10_capable;
      }
      ci.setWorkflow(false);
      ci.update();
   }
}

When I put it (even though I don't understand why would it need a semicolon on the 'if" statement) the error goes away but the script doesn't do what I expect it to do.

Could someone please assist. I just need to update the two fields, u_cpu_generation and u_processor_windows_10_capable on the Computer table, with data from the u_cpu_generation table. You are welcome to suggest changes on my script, that will enable me to achieve the desired result - still a learner in scripting!

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,


Please see below code:

var ci = new GlideRecord('cmdb_ci_computer');
ci.query();
while (ci.next()) {
   
   var gen = new GlideRecord("u_cpu_generation");
   gen.addQuery("u_gen_cpu_name",ci.cpu_name.toString()); // Hope these fields have same data type.
   gen.query();
   if(gen.next()){
      gs.log('Entering','Check');//Check if this log is coming or not.
         ci.u_cpu_generation = gen.u_gen_cpu_generation;
         ci.u_processor_windows_10_capable = gen.u_processor_windows_10_capable;
         ci.update();
   }
}

 

Thanks,
Ashutosh Munot

View solution in original post

11 REPLIES 11

It looks like, you are referring a custom table in your query named "u_cpu_generation".

 

But in query, you are using CI field in your add query. Are you sure, is there any field available on that table?

 

var gen = new GlideRecord("u_cpu_generation");
   gen.addQuery("ci",ci.sys_id.toString());

Hi Vinothkumar,

I realised that later and changed it to  gen.addQuery("u_gen_cpu_name",ci.cpu_name); with the hope of getting a match on cpu_name as I know for sure that cpu_name on Computer table has a matching record on the custom table. But this didn't do it either...

Kind Regards

Arnold

Hi Arnold,

The method setWorkflow(false) won't run in client script and will result in error whatever you try to do here if this script is present in client script.

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I 'm running this as a Scheduled Job. I just tried running it without a setWorkflow(false) method and still no desired result.....

Kind Regards

Arnol

Try with below script,

var ci = new GlideRecord('cmdb_ci_computer');
ci.query();
while (ci.next()) {
   
   var gen = new GlideRecord("u_cpu_generation");
   gen.addQuery("gen.u_gen_cpu_name",ci.cpu_name);
   gen.query();
   if(gen.next()){
      
         ci.u_cpu_generation = gen.u_gen_cpu_generation;
         ci.u_processor_windows_10_capable = gen.u_processor_windows_10_capable;
      
         ci.update();
   }
}