web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to copy a project including named ressources

(1) ShareShare
ReportReport
Posted on by

Hello all,

I am trying to copy a project including the named resources. The "Copy Project" in the ribbon menu only lets me copy without the named ressources.

The documentation states that an action "msdyn_CopyProjectV3" exists that can be used to copy a project including the named resources (Develop project templates with Copy Project | Microsoft Learn). I have tried to recreate the button in JS:

var Sdk = window.Sdk || {};
Sdk.CopyWithRessourcesRequest = function () { };
Sdk.CopyWithRessourcesRequest.prototype.getMetadata = function () {
    var metadata = {
        boundParameter: null,
        operationName: "msdyn_CopyProjectV3",
        operationType: 0 /* Function */,
        parameterTypes: {
            "SourceProject": {
                "typeName": "mscrm.crmbaseentity",
                "structuralProperty": 5 /* EntityType */,
            },
            "Target": {
                "typeName": "mscrm.crmbaseentity",
                "structuralProperty": 5 /* EntityType */,
            },
            "ReplaceNamedResources": {
                "typeName": "Edm.Boolean",
                "structuralProperty": 1 /* EntityType */,
            },
        },
    };
    return metadata;
};

// Copies the current project and opens the copied project in the same window
// require.js has been loaded by the command bar before making this call
async function copyProject(primaryControl, entityId) {
    console.log("Copy project: "   entityId);
    if (entityId) {
        var newProjectId = await Xrm.WebApi.createRecord("msdyn_project",{msdyn_subject:"TEST"});
        var copyWithRessourcesRequest = new Sdk.CopyWithRessourcesRequest();
        var sourceId = {
            "@odata.type": "Microsoft.Dynamics.CRM.msdyn_project",
            "quoteid": entityId
        };
        var targetId = {
            "@odata.type": "Microsoft.Dynamics.CRM.msdyn_project",
            "quoteid": newProjectId
        };
        copyWithRessourcesRequest.SourceProject = sourceId;
        copyWithRessourcesRequest.Target = targetId;
        copyWithRessourcesRequest.ReplaceNamedResources = false;

        await Xrm.WebApi.online.execute(copyWithRessourcesRequest);
    }
}

But when I call this function I get the following error:

Resource not found for the segment 'msdyn_CopyProjectV3'. Is this function not available in "Project Service Automation"?

I have the same question (0)
  • Suggested answer
    Haig Liu Profile Picture
    Microsoft Employee on at

    Hi Nicolas Krauter,

    I don't know much about the code on this, but it's clearly a formatting error.

    It is not being used correctly.

    So I suggest trying to use it like the example in the documentation:

    pastedimage1672968589098v1.png

  • Suggested answer
    Community member Profile Picture
    on at
    Hi Nicolas Krauter,
     
    Check the Action with XML document describes at API url like: https://[yourorg].crm.dynamics.com/api/data/v9.2/$metadata
    At [Dynamics 365 Project Operations], the sample code will like:
     
    var Sdk = window.Sdk || {};
    Sdk.CopyWithRessourcesRequest = function () { };
    Sdk.CopyWithRessourcesRequest.prototype.getMetadata = function () {
        var metadata = {
            boundParameter: "entity" /* bound action */,
            operationName: "msdyn_CopyProjectV3",
            operationType: 0 /* action */,
            parameterTypes: {
                "SourceProject": {
                    "typeName": "mscrm.msdyn_project",
                    "structuralProperty": 5 /* EntityType */,
                },
                "entity": {
                    "typeName": "mscrm.msdyn_project",
                    "structuralProperty": 5 /* EntityType */,
                },
                "ReplaceNamedResources": {
                    "typeName": "Edm.Boolean",
                    "structuralProperty": 1 /* PrimitiveType */,
                },
            },
        };
        return metadata;
    };
    
    // Copies the current project and opens the copied project in the same window
    // require.js has been loaded by the command bar before making this call
    async function copyProject(primaryControl, entityId) {
        console.log("Copy project: "   entityId);
        if (entityId) {
            var newProjectId = await Xrm.WebApi.createRecord("msdyn_project",{msdyn_subject:"TEST"});
            var copyWithRessourcesRequest = new Sdk.CopyWithRessourcesRequest();
            var sourceId = {
                "@odata.type": "Microsoft.Dynamics.CRM.msdyn_project",
                "msdyn_projectid": entityId
            };
            var entity = { entityType: "msdyn_project"};
            entity.id = newProjectId.id;
            copyWithRessourcesRequest.SourceProject = sourceId;
            copyWithRessourcesRequest.entity = entity;
            copyWithRessourcesRequest.ReplaceNamedResources = false;
    
            await Xrm.WebApi.online.execute(copyWithRessourcesRequest);
        }
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans