Extracting a particular (unknown) Project ID from a Task within many Projects

In Asana, we have a “Template” set up that we use for creating various projects. The template itself is called our “Website Project Template”. We use this template multiple times a day to create new projects.

After the new project is created, we then manually add an existing task to this new project. Long story short, this “existing task” is often in multiple projects at the same time (for various reasons). Anyway…

We are using Zapier to add this “existing task” to a Sheet row (and to update that row any time the “existing task” is edited). My goal is to ALSO be able to log the Project ID to the Sheet row as well. Currently, Zapier allows me to log ALL of the Project IDs of this “existing task”. However, I’m trying to only log ONE of the Project IDs.

As you may have guessed, I’m trying to log the Project ID of the new project (the one that was created via the Website Project Template). Is there any way to distinguish one Project from another one, so that only the project (of which was created via a template) is returned? It’s not possible for me to know what he name of the project is, or what it’s ID is, within the context of my Zapier zap. So I can’t use those as a searching method.

Alternatively, I was thinking if there was a way to “Tag” a template — so that the tag would also be added to any project that was created from that template — that would also be a useful way of finding a particular Project ID of a task.

Basically, I’m looking for a relatively simple way (likely via Zapier’s Javascript ability) to sift through the list of Projects that are returned from the task API; and then possibly look within each found project (via the Project API?) to grab the one that was created from a template (since none of the other projects were ever created via a template).

The only other method that I can think of is to add a Description to the template itself, and then ensure that the new project also gets that description during cloning. Then I could theoretically find the project of this task that has a particular description.

Any thoughts?

This is a tough one… I believe the project object does not hold the information that it was created from a template, maybe @Phil_Seeman can confirm.

The projects the task is already part of (and that you want to ignore) are they always the same? Cause you could filter the ids, I believe that is the same question you asked elsewhere on the forum.

Hi @FreshyJon,

Correct, it does not. (Having the ability to know not only if a project came from a template but which template is something I’ve requested; it would allow me to make a huge usability improvement in Flowsana. Hint hint @Ross_Grambo :slight_smile: )

That’s probably how I would do it.

The only other thing I can think of is using a project-level custom field. I’m not sure if it’s possible to include those in cloning; I’ve never tried it myself.

1 Like

Yes, this is a similar request to my previous post, but I’m thinking of a different way of finding the Project ID; rather than using a “process of elimination”.

The latest way I’d like to find the ID is actually a little different, and perhaps a tad bit easier?

Within the comma separated list of Project IDs (that belong to the task), I’d like to find the Project who has a Project Description of “Created from the #websiteprojecttemplate”.

So basically, I need a way with Zapier’s Javascript code (via the Asana API) to take the returned list of Projects, and then search within them for the Project that has that description.

FYI, this my current code that is able to output the list of Project IDs, as comma separated. https://i.imgur.com/jszKxC1.png

But I need to revise this code to then search each of those projects for the task with that description, and then output THAT project’s ID.

I’d suggest you use Custom External Data rather than the Description field. Unless you want it exposed to users, which could make sense.

The documentation is saying that Custom External Data is for tasks, and not projects. Regardless, I think I’m OK using the description field for now, to differentiate between the various projects. But that still leaves me stuck with figuring out how to adjust this code, so that it will search each of the found Project IDs and return the ID that happens to have the description in question.

Similar to this question, how would I take the data output of 999,555,123,888 and search within each of those Project IDs, so that it will find the one which has my description; and then output that Project ID?

1 Like

For your use case, do you already know the task ids? Per this part of the other question:

Basically, these Asana tasks would be in 4 different projects. I will always know the ID of 3 of those projects, and thus would like to omit those from the output. This will help me find and log the project ID of the new project that I’m looking for.

I will usually know the Project IDs of them, other than the one I’m trying to find.

For example, we add a task to Project Library 1, Project Library 2, Project Library 3, and also to a newly created Project. At this stage where the code is running, I won’t really know what the ID of the “newly created Project” is yet.

That’s why I wanted to search for it via its description. The “newly created Project” will always contain a particular sentence of Created from the #websiteprojecttemplate within its project description.

There’s an 80% chance that I’ll know all the other Project IDs (other than the one I’m trying to find). But there’s still the off-chance that the task will have been added to some other rogue Project (which I may not have accounted for).

That’s why I wanted to search for the Project that I know will have a particular project description, as opposed to saying “return the Project ID that doesn’t match these 3 other IDs”… because there’s the possibility that the task is also in another Project ID that I didn’t include in my “exclusion list”, per se.

Ah I see. That makes sense.

If you’re coming from the Task ID, I’d recommend you use https://app.asana.com/api/1.0/tasks/{id}?opt_fields=projects.notes . And then iterate through the projects until you find the one with the correct notes (description).

If you’re simply searching for the project not from the multi-homed task, I thinkkkk you can use /search. I’m unsure how reliable that would be. I believe you would have to iterate through the results and confirm it equals exactly what you’re expecting. Besides that I don’t know of a great way to go from this angle.

Yes, I do know the Task ID of the multi-homed task. So that method of https://app.asana.com/api/1.0/tasks/{id}?opt_fields=projects.notes is a good start.

Unfortunately, I’m not skilled enough in how to write code to iterate through the projects until I find the correct note, and then obtain that project’s ID.

I think it would need to be in Javascript to work with Zapier code filter. I have this so far: https://i.imgur.com/fUwKsM2.png

  • which will output the actual chunk of code, but I’d then need to iterate through each project notes value to find the one that contains #websiteprojecttemplate and then output the gid of that.

Do you know of a resource or area to request such a code snippet? Sounds like Stack Overflow may be a good place if nobody here is able to assist. Happy to pay wherever/whomever for some solid direction.

I think @Bastien_Siebman may be able to help you.

1 Like

Thanks Phil, I am barely starting myself with Zapier so probably not the best fit. However @paulminors or @abass might be better fit!

1 Like

At this point, I’m not sure it’s much of a Zapier hurdle as it is knowing proper Javascript/JSON to iterate/search the code of the API’s initial output, to grab the correct ID of the note being found.

Can you send me an email at siebmanb@gmail.com, and explain what you have as an input, what you want as an output, and I’ll write the code :wink: thanks!

1 Like

Along with @Bastien_Siebman’s help and Stack Overflow, here was my solution for this:

const res = await fetch('https://app.asana.com/api/1.0/tasks/' + inputData.uniqueID + '?opt_fields=projects.notes', {
	headers: {
		'Authorization': 'Bearer 0/0990jfg32jgUseYourOwnHere099sdfs'
	}
});
// Sends a JSON response composed of the specified data
const body = await res.json();
// Grabs the "data" content of the response
const data = body.data;
// Specify what we're going to look for within the response
const weLookForThis = '#websiteprojecttemplate';

const theProject = data.projects.find(p => p.notes.includes(weLookForThis));

if (theProject) {
	output = { id: theProject.gid };
} else {
	output = { id: 'NA' };
}
2 Likes