Forum Discussion

hina's avatar
hina
Contributor
2 months ago

The value of the variable is not updating

Hi,

I have a code below, I am retrieving the variable JobID from a string and then using the JobID in variable JobStatus. I have the JobStatus defined outside the while loop, initially it takes the correct value, but I am trying to update the JobStatus inside the while loop, but it's always displaying the same value it reads the first time. I have tried using Refresh() method with JobStatus and then trying to assign the Value, but nothing is working, JobStatus is not updating with new value. Please take a look at it.

function VerifyJob()
{
  // Get the job id
  var TempRecords = Sys["Process"]("C4")["WinFormsObject"]("C4Main")["WinFormsObject"]("panel1")["WinFormsObject"]("checkBoxAutoRefresh").Caption;
  var ArrRecords = TempRecords.split(':');
  var StrRecord = ArrRecords[4];
  var ArrJobID = StrRecord.split(' ');
  var JobID = ArrJobID[1];
  
  // Check Job Status
  var JobStatus = Sys["Process"]("C4")["WinFormsObject"]("C4Main")["WinFormsObject"]("panel1")["WinFormsObject"]("splitContainer1")["WinFormsObject"]("SplitterPanel", "", 1)["WinFormsObject"]("MainListView")["ListItem"](JobID)["Text"]("Job Status").Value;
  var count = 0;
  
  while(aqString["Compare"](JobStatus,"Done",false) != 0 && count != 15)
  {
    Delay(10000);
    count++;
    JobStatus = Sys["Process"]("C4")["WinFormsObject"]("C4Main")["WinFormsObject"]("panel1")["WinFormsObject"]("splitContainer1")["WinFormsObject"]("SplitterPanel", "", 1)["WinFormsObject"]("MainListView")["ListItem"](JobID)["Text"]("Job Status").Refresh();
    JobStatus = Sys["Process"]("C4")["WinFormsObject"]("C4Main")["WinFormsObject"]("panel1")["WinFormsObject"]("splitContainer1")["WinFormsObject"]("SplitterPanel", "", 1)["WinFormsObject"]("MainListView")["ListItem"](JobID)["Text"]("Job Status").Value;
    
    Log["Event"](JobStatus);
  }
  
  if(aqString["Compare"](JobStatus,"Done",false) == 0)
    Log["Event"]("Job " + JobID + " has successfully completed");
  else
    Log["Error"]("Job " + JobID + " has not successfully completed");

}

 

6 Replies

  • Have you tried to debug and step through your code?

    I suggest you use do...while statement instead of while, because you are checking that JobStatus twice. For example,

      // Check Job Status
      var count = 0; 
      do {
    	Delay(10000);
    	JobStatus = Sys["Process"]("C4")["WinFormsObject"]("C4Main")["WinFormsObject"]("panel1")["WinFormsObject"]("splitContainer1")["WinFormsObject"]("SplitterPanel", "", 1)["WinFormsObject"]("MainListView")["ListItem"](JobID)["Text"]("Job Status").Value;
        Log["Event"](JobStatus);
        count++;
      } while (aqString["Compare"](JobStatus, "Done", false) != 0 && count < 15);
    

     

  • What happens if you refresh at the Sys["Process"]("C4") level?

    You could also simplify the code using a WaitProperty method.

    TestObj.WaitProperty(PropertyNamePropertyValueWaitTime)

    Further: JobStatus is an object here... 

    var JobStatus = Sys["Process"]("C4")["WinFormsObject"]("C4Main")["WinFormsObject"]("panel1")["WinFormsObject"]("splitContainer1")["WinFormsObject"]("SplitterPanel", "", 1)["WinFormsObject"]("MainListView")["ListItem"](JobID)["Text"]("Job Status");

    So, JobStatus.Refresh() and JobStatus.Value will provide what you need further simplifying the code.  This also works well for...

    JobStatus.WaitProperty("Value", "Done", 10000); 

    This waits 10000 ms for "Value" to be "Done" and returns a boolean.

     

  • Also, investigate how this 'ListItem' behaves.  If you are adding a value, selecting a value or changing a value it may not behave the way you may expect at this level and value property may not be changing.