Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to copy a project including named ressources

Posted on by 59

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
    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
    Haig Liu 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans