Skip to content

Instantly share code, notes, and snippets.

@ryanmichaeljames
Last active September 16, 2019 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmichaeljames/8bd4dd65ec7d481b46c8ae2c3657dd53 to your computer and use it in GitHub Desktop.
Save ryanmichaeljames/8bd4dd65ec7d481b46c8ae2c3657dd53 to your computer and use it in GitHub Desktop.
Create operation with Xrm.WebApi.online.execute
var Sdk = window.Sdk || {};
/**
* Request to create a record
* @param {string} entityTypeName - The entity type name.
* @param {Object} payload - The entity payload.
*/
Sdk.CreateRequest = function (entityTypeName, payload) {
this.etn = entityTypeName;
this.payload = payload;
this.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {},
operationType: 2,
operationName: "Create",
};
};
};
// Construct a request object from the metadata
var request = new Sdk.CreateRequest("new_entity", { "new_name": "Foo Bar" });
// Use the request object to execute the function
Xrm.WebApi.online.execute(request).then(
(result) => {
if (result.ok) {
console.log(`${result.status} ${result.statusText}`);
}
},
(error) => {
console.log(error.message);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment