Siebel eScript : CountRecords() method returns 0 for every input Value

3.9k Views Asked by At

I am trying to create a business service which will return the count of records according to the status given as Input to it.
'Status' field is a static picklist field. Below is my Siebel eScript.

function getRecordsCount (Inputs, Outputs)
{
    var count=0;
    try
    { 
        var bo = TheApplication().GetBusObject(Inputs.GetProperty("boname"));
        var bc = bo.GetBusComp(Inputs.GetProperty("bcname"));
        var LOVText = TheApplication().InvokeMethod("LookupValue",Inputs.GetProperty("lovType"),Inputs.GetProperty("Status"));
        with (bc)
        {     

            ClearToQuery();
            SetSearchSpec("Status","\'"+LOVText+"\'");
            ExecuteQuery(ForwardOnly);
            count = CountRecords();
        }
      bc = null;
      bo = null;
    }
    catch (e)
    {
        throw (e);
    }
    finally
    {
        Outputs.SetProperty("Count",count);
    }
}
1

There are 1 best solutions below

1
AJPerez On

Depending on how your picklist is built, you might need to use this spec instead:

bc.SetSearchSpec("Status", "='" + status + "'");

It could also be a visibility problem. The user running the code might not have visibility for those 210 records. You can solve that by using this:

bc.SetViewMode(AllView);

If you want to be sure of what's happening, you can either enable the SQL spool tracing in your dedicated thick client and check the actual query it's executing... or, you can go to any service request applet and query yourself using the syntax [Status] = 'Active', or [Status] = 'ActiveLovText' (replacing ActiveLovText for whatever the LookupValue is returning).


Also, there are a few things you could improve in your code:

  • In this case, there is no need to escape your single quotes. "'" is fine.
  • If you catch an exception and just throw it again, you're doing nothing. You could aswell just remove those lines.
  • You are storing the count value in your PropertySet in a finally block, which you could reach even before the variable is initialized. Either declare it with an initial value, or place your SetProperty line elsewhere.
  • On the other hand, you should use the finally block to clear used objects, such as bc and bo. You're doind that inside your try block, meaning it won't be done if there is an exception. Not that it would matter in that case, but it's always good practise.

Considering all that, this is what the code should look like:

function ReturnStatusCount (Inputs, Outputs)
{
    var bo:BusObject;  // Remove the ":BusObject" and ":BusComp" parts if
    var bc:BusComp;    // they give you any trouble
    try {
        var status = Inputs.GetProperty("Status");
        var lovText = TheApplication().InvokeMethod("LookupValue", Inputs.GetProperty("lovType"), status);
        bo = TheApplication().GetBusObject(Inputs.GetProperty("boname"));
        bc = bo.GetBusComp(Inputs.GetProperty("bcname"));
        bc.ClearToQuery();
        bc.SetViewMode(AllView);
        bc.SetSearchSpec("Status", "='" + status + "'");  // status, or lovText maybe
        bc.ExecuteQuery(ForwardOnly);
        Outputs.SetProperty("Count", bc.CountRecords());
    } finally {
        bc = null;
        bo = null;
    }
}