Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Ribbon Button to Create Multiple records once in same entity using Plugin.

Posted on by Microsoft Employee

Hi,

I would like to have discussion on plugins. As I'm new to CRM dynamics 365, I would appreciate very much if you can help me in the plugins concept. 

My problem is - based on custom ribbon button for existing records in entity , I have to take information from current record and create multiple records at time in same entity. Can anyone tell me how to proceed with plugin ? I don't want to go with workflow at all. 

Isn't plugin with C# OR Plugin with JS ?

Reference materials , Articles or Sample Example will be helpful !

Thank you 

Deepthi Thotakura

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Ribbon Button to Create Multiple records once in same entity using Plugin.

    Thank you Fikri for your code. Its helps me to customize. I have doubt on this - how you are calling this JS from Ribbon button with Action(Process). Can you specify the function names at what fields you filled up so that I can understand the links or how its calling those function  

    Regards,

    Deepthi

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Ribbon Button to Create Multiple records once in same entity using Plugin.

    Hii,

    You can't complete your task by using plugin directly, at least you need to write JS just like the other answer above. Or if you want to use javascript only to accomplish your task, here i have the sample code:

    function CreateAccount(selectedIds) { 
        var accountId, accountName;
        var context = Xrm.Page.context; 
        var serverUrl = context.getClientUrl(); 
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; 
        var CRMObject = new Object(); 
        ///////////////////////////////////////////////////////////// 
        // Specify the ODATA entity collection 
        var ODATA_EntityCollection = "/new_troubleticketSet"; 
        ///////////////////////////////////////////////////////////// 
        // Define attribute values for the CRM object you want created 
        CRMObject.new_Subject = " ";
        accountName = " "; 
        CRMObject.new_TicketCategory = { Value: 100000001 };
        //CRMObject.Telephone1 = "12345"; 
        //CRMObject.Fax = "56456"; 
        //Parse the entity object into JSON 
        var jsonEntity = window.JSON.stringify(CRMObject); 
        //Asynchronous AJAX function to Create a CRM record using OData 
        $.ajax({ type: "POST", 
            contentType: "application/json; charset=utf-8", 
            datatype: "json", 
            url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection, 
            data: jsonEntity, 
            beforeSend: function (XMLHttpRequest) { 
                //Specifying this header ensures that the results will be returned as JSON. 
                XMLHttpRequest.setRequestHeader("Accept", "application/json"); 
            }, 
            success: function (data, textStatus, XmlHttpRequest) { 
                alert("success"); 
                var NewCRMRecordCreated = data["d"]; 
                accountId = NewCRMRecordCreated.new_troubleticketId;
    			
    			if (selectedIds != null && selectedIds != "") {
    			var strIds = selectedIds.toString();
    			var arrIds = strIds.split(",");
    			for (var indxIds = 0; indxIds < arrIds.length; indxIds++) {
    				UpdateContact(arrIds[indxIds], accountId, accountName);
    				}
    			alert("Selected Records Updated Successfully");
    			}
    			else {
    				alert("No records selected!");
    			}
              
            }, 
            error: function (XMLHttpRequest, textStatus, errorThrown) { 
                alert("failure"); 
            } 
        }); 
    }
    
    function UpdateContact(contactId, accountId, accountName) {
        var serverUrl = Xrm.Page.context.getClientUrl().toString();
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
        var ODATA_EntityCollection = "/IncidentSet";
    
        var objContact = new Object();
        // set the name of Account
        //objContact.Id = Xrm.Page.data.entity.getId();
    
        // set the Primary Contact lookup field
        objContact.new_TroubleTicketId= { Id: accountId, LogicalName: "new_troubleticket", Name: accountName };
    
        // Parse the entity object into JSON 
        var jsonEntity = window.JSON.stringify(objContact);
    
       $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + "(guid'" + contactId + "')",
            data: jsonEntity,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
    			XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
            },
            success: function (response) {
                if (response != null && response.d != null) {
                    alert(response.d.ContactId);
                }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
            }
        });
    }

    Our user want to create a case from multiple Ticket (custom entity) they choose on view and Update the Ticket by set their look up to the new Created Case.

    I used those javascript code to complete my task and by using ribbon workbench, i trigger the custom button to hit this code.  

    It's just the example code how to create a record to another entity. You need to modifiy this code to suit you requirement. 

  • SCV Profile Picture
    SCV 1,004 on at
    RE: Ribbon Button to Create Multiple records once in same entity using Plugin.

    Hi Deepthi,

    First create a plugin to create the records. Then create a custom action under Processes in CRM. Activate the action. Register your plugin on that action. Then Create a JavaScript function to call that custom action you created. On click of your ribbon button call this JavaScript action. Refer here for more details:

    sacconsulting.blogspot.com.au/.../how-to-call-plugin-from-javascript-or.html

  • Suggested answer
    Nick Plourde Profile Picture
    Nick Plourde on at
    RE: Ribbon Button to Create Multiple records once in same entity using Plugin.

    First, download the XrmToolbox. It has a nice ribbon editor. http://www.xrmtoolbox.com/

    Second, in your button, you have to call Javascript. In the Javascript, you can either update a field in your entity and save automatically. The field can be hidden. Or if you are more experienced, a workflow action. You should take the first option in your case.

    Third, create a plugin that will trigger when the field you chosen is updated. That plugin will do the job. Here is a decent tutorial: crmbusiness.wordpress.com/.../crm-2013-step-by-step-update-plugin-tutorial-using-the-crm-2013-development-toolkit

    The hardest part for you will be to create the plugin. If you haven't download the SDK. It has a template folder which helped me a lot when I started. This is the last version of it.

    www.microsoft.com/.../details.aspx

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: Ribbon Button to Create Multiple records once in same entity using Plugin.

    Hope you know how to invoke an Action using JS. (Ref: processjs.codeplex.com)

    gkhnmnts.blogspot.co.uk/.../crm-2016-custom-actions.html

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Ribbon Button to Create Multiple records once in same entity using Plugin.

    Thank you Gopalan for replying me back. Can you provide sample examples/ links related to your solution?

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: Ribbon Button to Create Multiple records once in same entity using Plugin.

    You can create an Action and a plug-in for this action. Invoke this action from your Ribbon button JavaScript function (pass the values from the current form)

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans