Skip to main content

Notifications

Announcements

No record found.

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"?

  • Suggested answer
    Community member Profile Picture
    on at
    How to copy a project including named ressources
    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);
        }
    }
  • Suggested answer
    Haig Liu Profile Picture
    Microsoft Employee on at
    RE: How to copy a project including named ressources

    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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

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

Overall leaderboard

Product updates

Dynamics 365 release plans