Create tasks from Project Online in Azure Function

147 views Asked by At

I need to create a Azure Function (c#) which reads the project's tasks from a Project Online site. After that, these tasks have to be created in other project in a different Project Online site.

I tried to do it with a logic app but the Project Online connector doesn't let me create all taks's properties.

Is there any .net library or any way to do it?

Thanks a lot.

1

There are 1 answers

0
Hury Shen On

It seems no c# library for us to use. I find a method in java code which maybe helpful to your question, we can also write java code in azure function to implement your requirements:

    /**
     * Add a task to a given project
     * @param projectID The GUID of the project
     * @param feature The text of the task
     * @param startDate The start date of the task
     * @return true/false on success (see Communications.lastError for details if failed)
     * @throws IOException
     * @throws UnsupportedEncodingException
     * @throws JSONException 
     */
    public boolean addTask(String projectID, String feature, String startDate) throws IOException, UnsupportedEncodingException, JSONException
    {
        JSONObject postData = new JSONObject();
        JSONObject parms = new JSONObject();
        UUID uuid = UUID.randomUUID();
        parms.put("Id", uuid.toString());
        parms.put("Name", feature);
        parms.put("Start", startDate);
        postData.put("parameters", parms);
        CloseableHttpClient httpclient = buildClient();
        String projURL = "/_api/ProjectServer/Projects('" + projectID + "')";
        String digest = getFormDigestValue();
        String fullurl = baseURL + projURL + "/Draft/Tasks/Add";
        HttpPost post = new HttpPost(fullurl);
        post.setHeader("Accept", "application/json;odata=verbose");
        post.setHeader("Content-Type", "application/json;odata=verbose");
        post.setHeader("X-RequestDigest", digest);
        post.setEntity(new StringEntity(postData.toString(0)));
        CloseableHttpResponse response = httpclient.execute(post);
        response.close();
        httpclient.close();
        if (response.getStatusLine().getStatusCode() == 200)
        {
            GUID = uuid.toString();
            return true;
        }
        GUID = "";
        hasError = true;
        lastError = response.getStatusLine().getReasonPhrase();
        return false;
    }

For more information about the method above, you can refer to this page.