Skip to main content
2-Explorer
June 14, 2016
Question

Need to schedule a job much like cron

  • June 14, 2016
  • 2 replies
  • 3868 views

Hi,

I am trying to write a program that will check WTUsers to see when they last logged into Windchill. I have code that worked against our LDAP, but ran outside of Windchill. We need to move this inside Windchill in order to keep WTUser and LDAP User in sync.  I've written Listeners before that will listen for an event, but I haven't written any scheduled services yet.  Is there any examples that can help me?  I can get the functionality working based on my previous code, but I'm not sure how to make it "scheduled" in Windchill.

2 replies

1-Visitor
June 14, 2016

It's pretty simple create a custom schedule job. The below link will be helpful and also refer the customizer guide, it is very well explained there too.

Creating custom scheduled jobs

tstacy2-ExplorerAuthor
2-Explorer
June 15, 2016

Never thought to look under Visualization for this info.  I'll take a look and see if it helps. Thanks.

1-Visitor
June 21, 2016

You can create your own Scheduling queue which can appear in Queue Management. Below is the example to create scheduling queue.

public static void processPublishingQueueEntry(WTObject wtobj, String objno, String objrev, WTObject wtobj2, String objno2, String objrev2) {

  SessionContext prev = SessionContext.newContext();

  try {

  SessionHelper.manager.setAdministrator();

  ReferenceFactory referencefactory = new ReferenceFactory();

  String sobj = referencefactory.getReferenceString(wtobj);

  String sobj2 = referencefactory.getReferenceString(wtobj2);

  QuerySpec spec = new QuerySpec(wt.queue.ScheduleQueue.class);

  spec.appendWhere(new SearchCondition(wt.queue.ScheduleQueue.class, "name", SearchCondition.EQUAL, "yourqueuename"));

  QueryResult result = PersistenceHelper.manager.find(spec);

  ScheduleQueue queue;

  if (result == null || result.size() < 1) {

  //Create the Queue.

  logger.debug("Creating a New Queue, as its not present.");

  queue = QueueHelper.manager.createScheduleQueue("yourqueuename");

  } else {

  logger.debug("Using the existing queue.");

  queue = (ScheduleQueue) result.nextElement();

  }

  WTUser adminUser = (WTUser) wt.session.SessionHelper.manager.getPrincipal();

  Class[] argTypes = {String.class, String.class, String.class, String.class, String.class, String.class};

  Object[] argValues = {sobj, objno, objrev, sobj2, objno2, objrev2};

  Timestamp timestamp = new Timestamp(System.currentTimeMillis() + 5000L);

  queue.addEntry(adminUser, "createViewable", "com.xxxx.services.xxxxService", argTypes, argValues, timestamp);

  } catch (Exception e) {

  e.printStackTrace();

  } finally {

  SessionContext.setContext(prev);

  }

    }

Hope this will help in creating job with in Windchill

tstacy2-ExplorerAuthor
2-Explorer
June 22, 2016

It did. Thanks.

1-Visitor
February 12, 2018

Hi,

I have same requirement. right now i have one class which extarct data  like WTPart from Windchill once in a day and place in to staging area out side Windchill,i am using cron job on daily basis to extract the Windchill data.

 

Can you please guide me to how i can use Schedulers instead of Cron job ?

 

Regards,

Vivek