Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Clone quote entity with all associated entities via Javascript

Posted on by Microsoft Employee

I need to clone the quote entity with all the associated entities on it (quote_details,...). I would like to go without C#/workflow code.

As far as I know, there is no function in the CRM-RestKit. 

My javascript-script looks as follows:

 CreateCopy: function () {
            Alert.showLoading();
            var id = Common.GetEntityId();
            SDK.REST.retrieveRecord(id,
                "Quote",
                null,
                "quote_details", // add more linked entities here
                function (quote) {
                    CreateNewQuoteAsCopy(quote);
                },
                function(msg) {
                    Common.ShowErrorMessage(msg);
                });
        },

        CreateNewQuoteAsCopy(quote) {
            quote.QuoteId = null;
            quote.Name = "COPY: " + quote.Name;
            SDK.REST.createRecord(quote,
                "Quote",
                function(newQuote) {
                    Alert.show("Quote copied",
                        "The quote was successfully copied",
                        [
                            new Alert.Button("OK")
                            //new Alert.Button("Open copy", Common.OpenEntity(id))
                        ],
                        "SUCCESS");
                },
                function(errorMsg) {
                    Common.ShowErrorMessage(errorMsg);
                });

        },

In the javascript I only copied the quote without related entities. Therefore I expanded the retrieve-query for the quote details, so that at least the products are copied. Unfortunately I get an error:

Bad Request: Error processing request stream. The payload must represent a valid array format for collections. 

So to speak: my solution does not work, can anyone answer me the question:

How do I clone the entity with all the associated entities? 

Thanks in advance

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Clone quote entity with all associated entities via Javascript

    Hi. worstcase. Any luck with this? Been trying to find out how to do this for a while now.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans