Highlighted
Absent Member.
Absent Member.
212 views

(SM) support tip: how to manage file using Java Script in Service Manager

There are sample java scripts which manipulate SM(Service Manager)'s file and four types of data manipulation like RDBMS, which are Select, Update, Delete and Insert:

 

 

1. SELECT
 - reference(ScriptLibary_name.function_name) : Change_KM_Upgrade.cmkmUpgrade

 - sample java script
    var fProbsummary = new SCFile("probsummary");
    var fSql = "number#\"" + "IM1001" + "\"";
    var rc = fProbsummary.doSelect( fSql );  // rc <= query result
   
    while ( rc == RC_SUCCESS )         
    {
     
     print("Number:" + fProbsummary.number );
     rc = fProbsummary.getNext();  
    }
    print("### end of job ###");
 
 - result in message tab
   ### end of job ###
   Number:IM10019
   Number:IM10018
   Number:IM10017
   Number:IM10016
   Number:IM10015
   Number:IM10014
   Number:IM10012
   Number:IM10011
   Number:IM10010

2. UPDATE
 - reference(ScriptLibary_name.function_name) : Change_KM_Upgrade.cmkmUpgrade

 - sample java script
    var fProbsummary = new SCFile("probsummary");
    var fSql = "number#\"" + "IM1001" + "\"";
    var rc = fProbsummary.doSelect( fSql );  // rc <= query result
   
    print("### start of job ###");
   
    while ( rc == RC_SUCCESS )         
    {
     
     print("Number:" + fProbsummary.number );
     print("Title:" + fProbsummary.brief_description );
   
    fProbsummary.brief_description = "updated:" + fProbsummary.brief_description;
     print("New Title:" + fProbsummary.brief_description );
     
     rc  = fProbsummary.doUpdate();
     if( rc != RC_SUCCESS ) print("Error in updating : " + fProbsummary.number );
     
     rc = fProbsummary.getNext();  
    }
    print("### end of job ###");
 
 - result in message tab
    ### end of job ###
    US/Mountain 06/17/14 23:52:21: Incident IM10019 has been updated by falcon
    New Title:updated:No internet connection available
    Title:No internet connection available
    Number:IM10019
    US/Mountain 06/17/14 23:52:20: Incident IM10018 has been updated by falcon
    New Title:updated:Printer keeps reporting "printer out of paper", while it's not
    Title:Printer keeps reporting "printer out of paper", while it's not
    Number:IM10018
    US/Mountain 06/17/14 23:52:20: Incident IM10017 has been updated by falcon
    New Title:updated:Virus scan reports a virus when receiving new e-mail
    Title:Virus scan reports a virus when receiving new e-mail
    Number:IM10017
    US/Mountain 06/17/14 23:52:20: Incident IM10016 has been updated by falcon
    New Title:updated:Impossible to login to webmail
    Title:Impossible to login to webmail
    Number:IM10016
    US/Mountain 06/17/14 23:52:20: Incident IM10015 has been updated by falcon
    New Title:updated:System can't recover from sleep-mode, reboot is needed
    Title:System can't recover from sleep-mode, reboot is needed
    Number:IM10015
    US/Mountain 06/17/14 23:52:19: Incident IM10014 has been updated by falcon
    New Title:updated:IE is not responding to users request
    Title:IE is not responding to users request
    Number:IM10014
    US/Mountain 06/17/14 23:52:19: Incident IM10012 has been updated by falcon
    New Title:updated:Error installing printer
    Title:Error installing printer
    Number:IM10012
    US/Mountain 06/17/14 23:52:19: Incident IM10011 has been updated by falcon
    New Title:updated:Virus scan notification: Multiple Virusses found
    Title:Virus scan notification: Multiple Virusses found
    Number:IM10011
    US/Mountain 06/17/14 23:52:19: Incident IM10010 has been updated by falcon
    New Title:updated:Network logon failure
    Title:Network logon failure
    Number:IM10010
    ### start of job ###

3. DELETE
 - reference(ScriptLibary_name.function_name) : ApprovalItem.deleteLineItemApproval

 - sample java script
    var fProbsummary = new SCFile("probsummary");
    var fSql = "number#\"" + "IM1001" + "\"";
    var rc = fProbsummary.doSelect( fSql );  // rc <= query result
   
    print("### start of job ###");
   
    while ( rc == RC_SUCCESS )         
    {
     
     print("Number:" + fProbsummary.number );
   
   if( fProbsummary.number == "IM10015" )
     {
      var rc_delete  = fProbsummary.doDelete();
      if( rc_delete == RC_SUCCESS ) print("IM10015 is deleted.");
     }
     rc = fProbsummary.getNext();  
    }
    print("### end of job ###");
 
 - result in message tab
   ### end of job ###
   Number:IM10019
   Number:IM10018
   Number:IM10017
   Number:IM10016
   IM10015 is deleted.
   Number:IM10015
   Number:IM10014
   Number:IM10012
   Number:IM10011
   Number:IM10010
   ### start of job ###

4. INSERT
 - reference(ScriptLibary_name.function_name) : ApprovalItem.deleteLineItemApproval

 - sample java script
    var fProbsummary = new SCFile("probsummary");
  
  fProbsummary.number="IM910001";
  fProbsummary.assignment="Application";
  fProbsummary.affected_item="Applications";
  fProbsummary.brief_description="title: created by custom java script";
  fProbsummary.action.push("description: created by custom java script");
  fProbsummary.category="incident";
  fProbsummary.subcategory="access";
  fProbsummary.product_type="authorization error";
  fProbsummary.initial_impact="1";
  fProbsummary.severity="1";
  
  var rc = fProbsummary.doInsert();
  if( rc == RC_SUCCESS )
  {
   print( fProbsummary.number + " is created" );
  }

 - result in message tab
   IM910001 is created
   US/Mountain 06/18/14 00:17:48:  Incident IM910001 has been opened by falcon


5. Miscellaneous
 1) call rad application
  - syntax : system.functions.rtecall( "{rad_application_name}", parameters .. )
  - example
    vars.$L_void=system.functions.rtecall("log",vars.$L_rc,"write on sm.log", "NULL");
 2) call system function
  - syntax : system.functions.{oob function name}
  - example
     system.functions.index( "OCML", fOperator.cap_exec );
 3) call function of 'Java Script Libaray'
  - syntax : system.library.{Java_Script_Library_name}.{function_name}( {parameters...} )
  - example
     system.library.KMCollection_Update.refreshIndexes();
    
 4) sample for one of customers
   // This is for adding 'OCML' capability words if not included
    var fOperator = new SCFile("operator");
    var fSql = "profile.incident=\"" + "incident analyst" + "\"";
    var rc = fOperator.doSelect( fSql );  // rc <= query result
   
    while ( rc == RC_SUCCESS )         
    {
      print("Login Name:" + fOperator.name );
      print("Capability words" + fOperator.cap_exec );
      
      if( system.functions.index("OCML", fOperator.cap_exec) == 0 )
      {
        print("This operator does not have OCML, so will add it");
        fOperator.cap_exec = system.functions.insert( fOperator.cap_exec, 1,1, "OCML" );
        var rc_update = fOperator.doUpdate();
       if( rc_update == RC_SUCCESS )
       {
         print(" successfully updated");
       }
       else
       {
         print("Error in updating");
       }
      }
      
      rc = fOperator.getNext();  
    }
    print("### end of job ###");

HP Support
If you find that this or any post resolved your issue, please be sure
to mark it as an accepted solution.
Please also give kudo if you find it interesting 🙂
Labels (1)
1 Reply
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Hi
I believe
The first example can be looking better 🙂

 

var fProbsummary = new SCFile("probsummary",SCFILE_READONLY);
fProbsummary.setFields(["number"]);
fProbsummary.doSelect("number#\"" + "IM1001" + "\"");
do {print("Number:" + fProbsummary.number );
   }while (fProbsummary.getNext()==0); 
print("### end of job ###");

 

 

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.