Planning

Get Involved. Join the Conversation.

Topic

    Brian M
    Random Groovy error "A method called by the script...Answered
    Topic posted October 14, 2019 by Brian MBlue Ribbon: 750+ Points, tagged Groovy, PBCS, Planning 
    39 Views, 2 Comments
    Title:
    Random Groovy error "A method called by the script failed on line..."
    Content:

    I have a groovy script that uses rest api to call a business rule then is suppose to check the run status until the business rule completes.  It appears to fail randomly in the section that checks the status of the business rule. 

    Error message: A method called by the script failed on line 34 (which refers to the line bolded red below).  

    Anything stand out? Or is there a different way I can approach checking the status of the running business rule?

     

    def jobStatus, jobId, i=0
    def finalStatus,finalDetails
    String urlContext = '/' + jobId
     
     HttpResponse<String> jsonResponse = operation.application.getConnection("RuleConnection").post()
     .header("Content-Type", "application/json")
     .body(json(["jobType" : "RULES", "jobName" : "Updater","parameters":Params ])).asString()
     
    def object = new JsonSlurper().parseText(jsonResponse.body) as Map
     
    jobStatus  = object.get('status')
    jobId  = object.get('jobId')
    finalDetails = object.get('details').toString()
    finalStatus = object.get('descriptiveStatus').toString()
     
    while(jobStatus==-1){
    HttpResponse<String> recjsonResponse = operation.application.getConnection("RuleConnection").get(urlContext).asString()

    def recObject = new JsonSlurper().parseText(recjsonResponse.body) as Map

     jobStatus = recObject.get('Status')
    finalDetails = recObject.get('details').toString()
    finalStatus = recObject.get('descriptiveStatus').toString()
         i++
     }
     
    println "Status of " + object.get('jobName') + ": " + finalStatus
    println "Details of " + object.get('jobName') + ": " + finalDetails
     
     

    Best Comment

    Anthony Manfredi

    Try this 

     
    //Get Status
     
     def object = new JsonSlurper().parseText(jsonResponse.body) as Map
     def myjobid=object.jobId.toString()
     
     
    //Keep Checking until status is not processing 
    while(object.status.toString() == "-1") { 
    //get the status of the current jobid
        HttpResponse<String> StatusResponse = operation.application.getConnection("JOBS").get("/$myjobid").asString()
        object = new JsonSlurper().parseText(StatusResponse.body) as Map
        println "Jobid:$object.jobId, Rule Name:$object.jobName, Rule Status:$object.descriptiveStatus"    
    }
     
     
     
    

    Comment

     

    • Anthony Manfredi

      Try this 

       
      //Get Status
       
       def object = new JsonSlurper().parseText(jsonResponse.body) as Map
       def myjobid=object.jobId.toString()
       
       
      //Keep Checking until status is not processing 
      while(object.status.toString() == "-1") { 
      //get the status of the current jobid
          HttpResponse<String> StatusResponse = operation.application.getConnection("JOBS").get("/$myjobid").asString()
          object = new JsonSlurper().parseText(StatusResponse.body) as Map
          println "Jobid:$object.jobId, Rule Name:$object.jobName, Rule Status:$object.descriptiveStatus"    
      }