Hi, I have two fields Actual Revenue and Actual Close date. On closing an Opportunity, values are set to this fields. When same record is reopen, it is observed that set values are set to empty.
On reopen Opportunity ribbon button ,I have code.
/// <reference path="SDK.WEBAPI.js" />
function ReOpenOpportunity(executionContext)//added
{
debugger;
var formContext = executionContext.getFormContext(); // added
var opptyId = formContext.data.entity.getId().replace('{', '').replace('}', '');//changed
var oppty = new Object();
oppty.aes_opportunityreopened = true;
SDK.WEBAPI.updateRecord(opptyId, oppty, "opportunities", function () { }, function () { });
}
this is SDK.WEBAPI.js
updateRecord: function (id, object, type, successCallback, errorCallback) {
///
/// Sends an asynchronous request to update a record.
///
////// A String representing the GUID value for the record to retrieve.
/// ////// A JavaScript object with properties corresponding to the Schema Names for
/// entity attributes that are valid for update operations.
/// ////// The Schema Name of the Entity type record to retrieve.
/// For an Account record, use "Account"
/// ////// The function that will be passed through and be called by a successful response.
/// Nothing will be returned to this function.
/// ////// The function that will be passed through and be called by a failed response.
/// This function must accept an Error object as a parameter.
/// this._stringParameterCheck(id, "SDK.WEBAPI.updateRecord requires the id parameter.");
this._parameterCheck(object, "SDK.WEBAPI.updateRecord requires the object parameter.");
this._stringParameterCheck(type, "SDK.WEBAPI.updateRecord requires the type parameter.");
this._callbackParameterCheck(successCallback, "SDK.WEBAPI.updateRecord requires the successCallback is a function.");
this._callbackParameterCheck(errorCallback, "SDK.WEBAPI.updateRecord requires the errorCallback is a function.");
if (type.slice(-1) != "s") {
type = type + "s";
}
var req = new XMLHttpRequest();
req.open("PATCH", encodeURI(this._WebAPIPath() + type + "(" + id + ")"), true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 204 || this.status == 1223) {
successCallback();
}
else {
errorCallback(SDK.WEBAPI._errorHandler(this));
}
}
};
req.send(JSON.stringify(object));
},
deleteRecord: function (id, type, successCallback, errorCallback) {
///
/// Sends an asynchronous request to delete a record.
///
////// A String representing the GUID value for the record to delete.
/// ////// The Schema Name of the Entity type record to delete.
/// For an Account record, use "Account"
/// ////// The function that will be passed through and be called by a successful response.
/// Nothing will be returned to this function.
/// ////// The function that will be passed through and be called by a failed response.
/// This function must accept an Error object as a parameter.
/// this._stringParameterCheck(id, "SDK.WEBAPI.deleteRecord requires the id parameter.");
this._stringParameterCheck(type, "SDK.WEBAPI.deleteRecord requires the type parameter.");
this._callbackParameterCheck(successCallback, "SDK.WEBAPI.deleteRecord requires the successCallback is a function.");
this._callbackParameterCheck(errorCallback, "SDK.WEBAPI.deleteRecord requires the errorCallback is a function.");
if (type.slice(-1) != "s") {
type = type + "s";
}
var req = new XMLHttpRequest();
req.open("DELETE", encodeURI(this._WebAPIPath() + type + "(" + id + ")", true));
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 204) {
successCallback();
}
else {
errorCallback(SDK.WEBAPI._errorHandler(this));
}
}
};
req.send();
},
*This post is locked for comments