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 :
Microsoft Dynamics CRM (Archived)

Workflow to create a custom entity record and open the created entity record from a Ribbon Button

(0) ShareShare
ReportReport
Posted on by 45

Hi Team,

I have a custom entity call Service Agreement. I need to have a button in Quote form to "Create Service Agreement". I already created a workflow to create a Service agreement from Quote entity. Can you experts help me to figure out how I can open the created entity form from clicking that "Create Service Agreement" button. 

Is there a non coded way?

Or if I use a JavaScript can anybody suggest a supported code?

Thank you heaps in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    NODAL Profile Picture
    860 on at

    Hi Buddhi,

    You need to consider below points before finalizing approach.

    1) Do you want to create record or just open create form with prefilled values.

    2) on every click of button you want to create a new record or if there is already one then you want to open that.

    Regards,

    Ketan

  • Buddhi Thathsala Perera Profile Picture
    45 on at

    Hi Ketan,

    1) I need to create the record and then open the created record.

    2) I want to open the created record from the workflow (workflow may trigger on a Boolean field on the form, we can change the Boolean field from button but I want to open that record)

    I am not sure this is possible. I am all ears for your suggestions

    Thank you

  • Suggested answer
    NODAL Profile Picture
    860 on at

    Hi Buddhi,

    You can achieve this through javascript.

    1) create a command for your button and JavaScript function

    2)first retrieve already created service agreement. 

    If found open that else create new using webapi

    Create call will give you guid which you can open. 

    You could use CRM Rest Builder so that you can quickly create retrieve and create web api request. 

    Download from below link 

    https://github.com/jlattimer/CRMRESTBuilder/releases/tag/2.6.0.0

    Note: select Xrm.Webapi while creating requests in Rest Builder. 

    Regards, 

    Ketan

  • Buddhi Thathsala Perera Profile Picture
    45 on at

    Hi Ketan,

    Thank you for the reply. I just downloaded and imported the solution. Do you know a proper guide document to use this Rest Builder?

    Thank you

    Kend Regards

    Buddhi

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

    Hi Buddhi,

    As suggested by Ketan, you could use rest api (using rest builder) or else you also use Xrm.WebAPi library to create and open record in crm using JS.

    Please refer below url to use rest builder:

    www.wipfli.com/.../tc-crm-rest-builder-dynamics-crms-web-api

    somacrm.wordpress.com/.../

    If you want you could use custom action as well. Inside below steps I have mentioned to call action using js

    pravinpawarweb.wordpress.com/.../

  • Buddhi Thathsala Perera Profile Picture
    45 on at

    Hi Guys,

    Thank you for your help so far.

    I wrote this following code to retrieve Quote entity data and create a "Service Agreement" custom entity record.

    It works fine but now I need to Retrieve Opportunity lookup field and while creating the new service agreement record I need to fill the opportunity field there.

    I have commented out this

    entity["bin_opportunity@odata.bind"] = "/opportunities(lookupValue[0].id)";

    as it gives me following error

    ')' or ',' expected at position 12 in '(lookupValue[0].id)'.

    I tried with ( ) but no luck. Do you guys have any suggestions?

    Entire code

    function CreateServiceAgreement() {

       debugger;

       //Retrive Quote data

       var QuoteID = Xrm.Page.data.entity.getId();

       Xrm.WebApi.online.retrieveRecord("quote", QuoteID, "?$select=_accountid_value,name,_opportunityid_value").then(

           function success(result) {

               debugger;

               var _accountid_value = result["_accountid_value"];

               var _accountid_value_formatted = result["_accountid_value@OData.Community.Display.V1.FormattedValue"];

               var _accountid_value_lookuplogicalname = result["_accountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

               var name = result["name"];

               alert(name);

               var _opportunityid_value = result["_opportunityid_value"];

               var _opportunityid_value_formatted = result["_opportunityid_value@OData.Community.Display.V1.FormattedValue"];

               var _opportunityid_value_lookuplogicalname = result["_opportunityid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

               //create Service Agreement

               var entity = {};

               entity.bin_name = name;

               var lookupValue = new Array();

               lookupValue[0] = new Object();

               lookupValue[0].id = _opportunityid_value; // GUID of the lookup id

               lookupValue[0].name = _opportunityid_value_formatted; // Name of the lookup

               lookupValue[0].entityType = _opportunityid_value_lookuplogicalname; //Entity Type of the lookup entity

               alert(lookupValue[0].id);

               //entity["bin_opportunity@odata.bind"] = "/opportunities(lookupValue[0].id)";

               Xrm.WebApi.online.createRecord("bin_serviceagreement", entity).then(

                   function success(result) {

                       var newEntityId = result.id;

                       //below code is used to open the created record

                       var windowOptions = {

                           openInNewWindow: true

                       };

                       //check if XRM.Utility is not null

                       if (Xrm.Utility != null) {

                           //open the entity record

                           Xrm.Utility.openEntityForm("bin_serviceagreement", newEntityId, null, windowOptions);

                       }

                   },

                   function (error) {

                       Xrm.Utility.alertDialog(error.message);

                   }

               );

           },

           function (error) {

               Xrm.Utility.alertDialog(error.message);

           }

       );

    }

  • Buddhi Thathsala Perera Profile Picture
    45 on at

    community.dynamics.com/.../965763

  • Suggested answer
    Buddhi Thathsala Perera Profile Picture
    45 on at

    Solved check the comments.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans