Question

The basic need is to determine Object Manager's name for current running task. Additional benefit would be if we could also get Task Id, Component Name (in general), Component Group Name, Server Name and Enterprise Name.

Actually there is a solution provided here, but it has serious limitations. As long as it uses Server Admin buscomps that are pure in-memory objects and does not support query by example, we have to iterate through all records. That can result in performance issues on production server with hundreds or even thousands of active tasks. Is there any other way we can get that information?

Was it helpful?

Solution

We can achieve the goal using Server Task Persistance component. This component (introduced in version 8.0), when enabled, will store component tasks information into S_SRM_TASK_HIST table (respective buscomp for this table is "Enterprise Task History"). The mentioned business component is table based, so we can query in usual way. There are several parameters that set up component behavior. I.e. parameter "DeleteEventHistoryInterval" controls the duration of tasks info kept (24 hours by default) and parameter "EnableEventHistory" controls if tasks information is saved for respective Server Component.

So for following eScript code to work, Server Task Persistance component should be up and running, task history saving should be enabled for target components as well. We get Task Id in the sample, with little modifications we can also obtain Component Name, Component Group Name, Server Name, Enterprise Name and other useful data (for full list of fields stored, see respective buscomp definitions in Siebel Tools).

function Service_PreInvokeMethod (MethodName, psInputs, psOutputs)
{
     if (MethodName == "Run")
     {
          var ProcessId = 0;
          var ThreadId = 0;
          var TaskId = 0;
          var EntFound = false;
          var SrvFound = false;
          var TaskFound = false;
          //Following two lines assume that Siebel server is running on Solaris OS
          //Change as appropriate for other OS'es
          ProcessId = SElib.dynamicLink("libsys.so", "getpid");
          ThreadId = SElib.dynamicLink("libpthread.so", "pthread_self");

          var boServerAdmin = TheApplication().GetBusObject("Server Admin");
          var bcEnterpriseServer = boServerAdmin.GetBusComp("Enterprise Server");
          var bcServerServer = boServerAdmin.GetBusComp("Server Server");
          var bcTaskHistory = boServerAdmin.GetBusComp("Enterprise Task History");

          with(bcEnterpriseServer)
          {
               ClearToQuery();
               ExecuteQuery(ForwardOnly);
               EntFound = FirstRecord();
               while (EntFound)
               //For all Enterprises
               {
                    with(bcServerServer)
                    {
                         ClearToQuery();
                         ExecuteQuery(ForwardOnly);
                         SrvFound = FirstRecord();
                         while (SrvFound)
                         //For all Servers
                         {
                               with(bcTaskHistory)
                              {
                                   ActivateField("O/S Proc Id");
                                   ActivateField("Thread Id");
                                   ActivateField("Task Id");
                                   ClearToQuery();
                                   SetSearchSpec("O/S Proc Id", ProcessId);
                                   SetSearchSpec("Thread Id", ThreadId);
                                   SetSortSpec("Task Start Time(DESCENDING)");
                                   ExecuteQuery(ForwardOnly);
                                   TaskFound = FirstRecord();
                                   if (TaskFound)
                                   {
                                        //This sample returns TaskId
                                        TaskId = GetFieldValue("Task Id");
                                        psOutputs.SetProperty("TaskId", TaskId);
                                        return (CancelOperation);
                                   }
                              }
                              SrvFound = NextRecord();
                         }
                    }
                    EntFound = NextRecord();
               }
          }
          psOutputs.SetProperty("TaskId", NaN);
          return (CancelOperation);
     }
     return (ContinueOperation);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top