Support Article

How to capture the name of the calling activity

SA-2188

Summary



How to capture the name of the activity, which calls a current activity, without passing that name as parameter?

Resolution



Include the code given below in the Java step of the called activity. actName variable gives the calling activity name.
 
     
String javaClassname = "";
      StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
      int j=0;
      for(int i=0; i< stacktrace.length ; i++){
     
      if(stacktrace[i].getMethodName()=="perform"){
      j++;
      }
      if(j==2){
      javaClassname = stacktrace[i].getClassName();
      break;
      }
      //oLog.infoForced("classname : "+stacktrace[i].getClassName() + " and method name : "+stacktrace[i].getMethodName() );
     
      
      }
      //oLog.infoForced("javaClassName : "+javaClassname );
      int startIndex = javaClassname.indexOf("_action_")+8;
      //oLog.infoForced("index start : "+startIndex );
      int endIndex = javaClassname.lastIndexOf("_");
      //oLog.infoForced("index end: "+endIndex );
      String actName = javaClassname.substring(startIndex, endIndex );
      //oLog.infoForced("act name = "+actName);
Suggest Edit

Published November 22, 2016 - Updated October 8, 2020


60% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.