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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to open created record?

(0) ShareShare
ReportReport
Posted on by 10

I have created a custom "create order" button on quote and created an action to populate details from quote to order

I triggered action using javascript

function createOrder(){
debugger;
guid = Xrm.Page.data.entity.getId();

var parameters = {};
var quote = {};
quote.quoteid = guid; //Delete if creating new record 
quote["@odata.type"] = "Microsoft.Dynamics.CRM.quote";
quote["transactioncurrencyid@odata.bind"] = "/transactioncurrencies(00000000-0000-0000-0000-000000000000)";
quote["pricelevelid@odata.bind"] = "/pricelevels(00000000-0000-0000-0000-000000000000)";
parameters.quote = quote;

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/cr4a6_CreateOrder", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
alert("success");

} else {
Xrm.Utility.alertDialog(this.statusText);
}

}
};
req.send(JSON.stringify(parameters));

}

This code is creating a new order record in the background but i need to open that from on click of that same button.

Can anyone please help me.

Thank you.

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    I did something like this recently, but it wasnt a button, should still work.

    Try this in your success section, but you may want to setup something to make in sync instead of async or else its kind of racing itself to display data or an empty-ish order.  This will open the record.

                           var pageInput = {

               pageType: "entityrecord",

               entityName: "opportunity",

               entityId: newOptyID //guid of your new record, mine was opportunity.

           };

           var navigationOptions = {

               target: 2,

               height: {

                   value: 80,

                   unit: "%"

               },

               width: {

                   value: 70,

                   unit: "%"

               },

               position: 1

           };

                                   Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(

    function success()

    {

       // Run code on success

    },

    function error()

    {

       // Handle errors

    });

    If timing becomes an issue, you can look into using an async function with await/promises added in.

  • Ashok__ Profile Picture
    10 on at

    Could you please tell me how to read the guid of newly created record from that same javascript code.

    and step given in action is to create a record - order

  • Suggested answer
    Community Member Profile Picture
    on at

    Mine come from the result variable when im creating via webapi.

    Xrm.WebApi.createRecord("ENTITYNAME", data).then(

               function success(result)

               {

                   if (result)

                   {

                       resolve(result);

                   }

                   else

                   {

                       resolve(null);

                   }

               },

  • Suggested answer
    Community Member Profile Picture
    on at

    Sorry, I didnt reread your original code, it should be returned from your request.

  • Community Member Profile Picture
    on at

    Hi Ashok,

    You can use following code to js to open new form when you click the button:

    Xrm.Navigation.openForm(entityFormOptions,formParameters).then(successCallback,errorCallback);

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-navigation/openform

    you can refer following link to know more steps:

    https://www.advaiya.com/blog/dynamics-365-crm-passing-parameters-using-ribbon-button-with-customized-ribbon-workbench/

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Hi Ashok,

    You can try with Xrm.WebApi to get Id of newly created record and then you can open that record

    var entity = {};
    entity.name = "John Smith ";
    entity.address1_city = "Newyork ";
    
    Xrm.WebApi.online.createRecord("account", entity).then(
        function success(result) {
            var newEntityId = result.id;
        },
        function(error) {
            Xrm.Utility.alertDialog(error.message);
        }
    );

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans