Finding a job within a Group

ucabrera (1 post)
January 10, 2019 05:24 AM
Accepted Answer

Hello there,

How could I find an specific job name into a group?

I'm already getting all jobs into group but from there I don't know how 'filter' a job name.

 

Thanks.

Post moved from topic Getting all Groups within a Group
Bill Staff (599 posts)
January 10, 2019 08:47 AM
Accepted Answer

I moved your post to a new topic since it doesn't seem to be a continuation of the topic where you posted it.

The simplest way to get a specific job if you already know the group name and job name is:

context.GetJob("group name\job name");

If you want to iterate through all the jobs for a group that you have already fetched, you can use something like this:

var jobs=group.GetJobs(ObjectFetchOptions.StubsOnly,false)
foreach(var job in jobs)
{
    if(job.Name.Equals("target job name", StringComparison.OrdinalIgnoreCase    ))
    {
        //that's your job
    }
}

But GetJob is going to be more efficient.

 

Replies are disabled for this topic.