Two entities, Author (dab_author) and Book (dab_book) with a 1:N relationship between them.
The challenge is to create an new book for a particular author, from the author form.
var createNewBook = function() { url = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/dab_bookSet"; author = Xrm.Page.data.entity.getId(); dab_book = {}; dab_book.dab_name = "Odata entity creation test"; dab_BooksId = {}; dab_BooksId.Id = author; dab_BooksId.LogicalName = "dab_author"; dab_book.dab_BooksId = dab_BooksId; book = window.JSON.stringify(dab_book); createBook(book, url).done(process) } var createBook = function(book, url) { return $.ajax({ type:"POST", contentType:"application/json;charset=utf-8", datatype:"json", data:book, url:url, beforeSend:function(x){x.setRequestHeader("Accept","application/json")}, }); } var process = function(data){ var entity = data.d; alert("Created new Book. Id:" + entity.dab_bookId); }
Also, jquery needs to be loaded if you are using Dynamics CRM 2011
No comments:
Post a Comment