There are two entity, Entity A and Entity B. I just created custom button using ribbon workbench and placed the button in the home page of the Entity A.
The main idea is simple.
First, user will select one or more records that displayed in the views of Entity A
Second, user press the custom button. The custom button contains script to create records in Entity B. When created this record, script will get GUID this new record. Then update look up in the selected records based on the GUID of the new records.
Here the script:
function CreateTicket(selectedIds){ var select = selectedIds.toString(); var guidTicket; var ticObj = new Object(); ticObj.lnkt_name = " "; ticObj.new_tickettype = 100000001; //Create Record Xrm.WebApi.createRecord("lnkt_troubleticket", ticObj).then( function success(result) { guidTicket = result.id; //Make sure that ticket has been created Xrm.Utility.alertDialog("Ticket created with ID: " + guidTicket + "ID: " + select); If(select != null && select != "") { var arrIds = select.split(","); for(var indxs = 0; indxs < arrIds.length; indxs++) { //Call Update Function UpdateCase(guidTicket, arrIds[indxs]); } alert("All selected records Updated"); } else { alert("No records has been selected !"); } }, function (error) { Xrm.Utility.alertDialog(error.message); } ); } function UpdateCase(guidTicket, selectId){ //Create object for update var ticketObj = new Object(); ticketObj["lnkt_TroubleTicketId@odata.bind"] = "/lnkt_troubletickets(" + guidTicket + ")"; Xrm.Utility.alertDialog("Ticket ID: "+ guidTicket +"\nCaseID : " + selectId); // update the record Xrm.WebApi.updateRecord("incident", selectId, ticketObj).then( function success(result) { Xrm.Utility.alertDialog("Case Updated"); // perform operations on record update }, function (error) { Xrm.Utility.alertDialog(error.message); // handle error conditions } ); }
The script looks not working. Because nothing happen when i press the custom button after select the record.
I have checked that both var select and var guidTicket contains data.
But if i remove the "BOLD" scripts. This is what i get
Need your help :)
*This post is locked for comments