Getting a fully qualified job name from the job ID.

phavanagi (15 posts)
August 10, 2017 08:43 AM
Accepted Answer

Hi Bill,

Is there a method that would give me the job name if I provide it with the Job ID? I did look through the documentation but could not find any. Kindly let me know if I am missing something.

Bill Staff (602 posts)
August 10, 2017 09:08 AM
Accepted Answer

The Job ID (displayed in the job properties in the Console) is the OID in the API. You would convert the value to a GUID, then use DataContext.GetObject to get the job for the OID (I don't think DataContext.GetJob works if you give it an OID instead of a name).

Cast the result to type Job, then use Name or FullyQualifiedName to get the name.

phavanagi (15 posts)
August 10, 2017 09:34 AM
Accepted Answer

Thanks Bill,

I did try that, Below is the code, but it gives an error as Cannot implicitly convert type '... .ADTOblect' to ' ... .Job'.

Can you let me know how do I cast it?

using (DataContext context = connection.NewDataContext())
                    {
                        OID o = new OID("c8092893-0136-4271-b88d-4356de7c51a8");
 
                        Job obj = context.GetObject(o); // error on this line
 
//Rest of the code
Bill Staff (602 posts)
August 10, 2017 09:49 AM
Accepted Answer

You need an explicit cast:

Job obj = (Job)context.GetObject(o);

or

Job obj = context.GetObject(o) as Job;

 

phavanagi (15 posts)
August 10, 2017 10:22 AM
Accepted Answer

Yeah, I did cast it, but it still gives me a null response.

OID o = new OID("c8092893-0136-4271-b88d-4356de7c51a8"); -> Is this the right way to declare the JOB Id i.e. OID in the API ?

 

string connectionDesciptor = Scheduler.BuildConnectionDescriptor(ConfigurationManager.AppSettings["AdTempusServer"],Int32.Parse(ConfigurationManager.AppSettings["AdTempusPort"]),""  );
using (Scheduler connection = Scheduler.Connect())
       {
              using (DataContext context = connection.NewDataContext())
                  {
                     OID o = new OID("118827ab-a00d-40c9-8c36-b8fb6f93014d");
 
                      Job obj = (Job)context.GetObject(o);
 
 
                      Job job = context.GetJob(obj.Name);
                  }

Doing something like this.

JOB ID is : {118827ab-a00d-40c9-8c36-b8fb6f93014d} when I view in the Console. Kindly let me know where I am going wrong.

 

Bill Staff (602 posts)
August 10, 2017 11:31 AM
Accepted Answer

Sorry! I didn't answer correctly, and I didn't pay attention to that part of your code. The Job ID doesn't translate straight to the OID: An OID is the object ID (GUID) plus a class ID, and you're missing the class ID. I'm surprised something didn't throw an exception since the string value you're passing it isn't a valid OID.

You need:

OID o=new OID(ClassID.Job, New Guid("118827ab-a00d-40c9-8c36-b8fb6f93014d"));

 

phavanagi (15 posts)
August 10, 2017 11:37 AM
Accepted Answer
Thanks Bill, Appreciate your help :)
phavanagi (15 posts)
August 10, 2017 11:54 AM
Accepted Answer

Also Bill,

Is there a way to retrieve the Job ID from the fully qualified job name?

Bill Staff (602 posts)
August 10, 2017 12:08 PM
Accepted Answer
Use GetJob to get the job based on the name. Job.OID.ObjectID gives you the GUID that is shown as the Job ID in the Console.

Replies are disabled for this topic.