Trying to access the cmdb_ci_computer table through Workflow (IF Activity)

fpuzon
Tera Contributor

Hi everyone,

I have a requirement to update one of our workflows to trigger a new catalog tasks IF 3 conditions are met.   The three include:
1) IF a checkbox on the sys_user table is set to true
2) IF a CI assigned to the current user has the chassis type set to 'Desktop' on the cmdb_ci_computer table

3) IF a CI assigned to the current user has the install status set to 'Installed' on the cmdb_ci_computer table

I'm able to get #1 accomplished just fine, it's # 2 and #3 that I'm having trouble with.   I have attached some screenshot's that hopefully better explains my requirement.   I   have also attached the if 'activity in the workflow that I started with.   Any help is appreciated.   Thanks everyone!

Fred

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Fred,



Please find the modified code below as per your req.


answer = ifScript();


var chasisStatus = CheckChasis();


var installStatus = CheckInstall();


function ifScript()


{


  if(current.variables.u_lit_hold && chasisStatus && installStatus)


  {


  return true;


  }


  else


  {


  return false;


  }


}




function CheckChasis()


{


  var gr = new GlideRecord('cmdb_ci_computer');


  gr.addQuery('assigned_to', gs.getUserID());


  gr.addQuery('chassis_type', 'Desktop');


  gr.query();


  if(gr.next())


  {


  return 'true';


  }


}


function CheckChasis()


{


  var gr = new GlideRecord('cmdb_ci_computer');


  gr.addQuery('assigned_to', gs.getUserID());


  gr.addQuery('install_status', 1);


  gr.query();


  if(gr.next())


  {


  return 'true';


  }


}







Note: Untested code.


View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Fred,



Please find the modified code below as per your req.


answer = ifScript();


var chasisStatus = CheckChasis();


var installStatus = CheckInstall();


function ifScript()


{


  if(current.variables.u_lit_hold && chasisStatus && installStatus)


  {


  return true;


  }


  else


  {


  return false;


  }


}




function CheckChasis()


{


  var gr = new GlideRecord('cmdb_ci_computer');


  gr.addQuery('assigned_to', gs.getUserID());


  gr.addQuery('chassis_type', 'Desktop');


  gr.query();


  if(gr.next())


  {


  return 'true';


  }


}


function CheckChasis()


{


  var gr = new GlideRecord('cmdb_ci_computer');


  gr.addQuery('assigned_to', gs.getUserID());


  gr.addQuery('install_status', 1);


  gr.query();


  if(gr.next())


  {


  return 'true';


  }


}







Note: Untested code.


Hello Fred,



Let me know if that answered your question. If so, please mark it as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list. Thank you


Hi Pradeep,


Thank you for the quick reply and for the sample code!   I just got done testing this and was able to get it to behave the way I wanted, except for when the 'Installed Status' is set to a value of '1'.   Even when the installed status is NOT set to '1' it still triggers the task.   I even updated the GlideRecord to point to 'cmdb' (Base Configuration) instead of 'cmdb_ci_computer as the 'install status' is not on this table it turns out.   I'll play with it some more, but this got me a lot closer to where I need to be.   Thanks again!



Fred


snehabinani26
Tera Guru

HI Fred,



Please find the code below



  1. answer = ifScript();  
  2. function ifScript() {
  3. var chasisStatus = false;
  4. var gr = new GlideRecord('cmdb_ci_computer');  
  5.   gr.addQuery('assigned_to', gs.getUserID());  
  6.   gr.addQuery('chassis_type', 'Desktop');  
  7.   gr.query();  
  8.   if(gr.next())  
  9.   {  
  10.   chasisStatus = true;  
  11.   }  
  12.  
  13. var installStatus = false;
  14. var gr1 = new GlideRecord('cmdb_ci_computer');  
  15.   gr1.addQuery('assigned_to', gs.getUserID());  
  16.   gr1.addQuery('install_status', 1);  
  17.   gr1.query();  
  18.   if(gr1.next())  
  19.   {  
  20.   installStatus = true;  
  21.   }  
  22.   if(current.variables.u_lit_hold && chasisStatus && installStatus)  
  23.   {  
  24.   return 'yes';  
  25.   }  
  26.   else  
  27.   {  
  28.   return 'no';  
  29.   }  
  30. }  


Hope this helps you.