"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

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

Hi Ashutosh,

This is working perfectly!

Thank you very much for your help - much appreciated.

Kind Regards

Arnold