Hello! I need your help!
Our client needs a new button to reset a Quote from Won back to Draft > Active > Closed Revised (and create revision). I tried to do this in C# first, and succeeded but the new revision wouldn't open (can't do this with server side code). So I have redone this in JavaScript and have reached the same point. I am able to bipass going to Draft and Active stages and go straight to Closed Revised, then using Web API create the new revision. This all works well so far. There is a button using the ReviseQuote function. Only thing is I need the newly created revision to open, but so far I can't make it work. Below is my code:
function ReviseQuote() {
debugger
var entityId = Xrm.Page.data.entity.getId().substring(1, 37);
var CloseQuoteData = {
//0 Draft 1 In Progress
//1 Active 2 In Progress
//3 Closed 7 Revised
"statecode": 3,
"statuscode": 7
};
Xrm.WebApi.updateRecord("quote", entityId, CloseQuoteData).then(function success(result) {
Xrm.Page.data.refresh(true);
}, function (error) {
Xrm.Page.data.refresh(true);
});
var windowOptions = {
openInNewWindow: true
};
var CreatedEntityID = null;
var parameters = {};
parameters.QuoteId = Xrm.Page.data.entity.getId().substring(1, 37);
parameters.ColumnSet = { AllColumns: true, Columns: [] };
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/ReviseQuote", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "return=representation");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
CreatedEntityID = newEntityId; //Assign the value to the local variable
var results = JSON.parse(this.response);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(parameters));
Xrm.Utility.openEntityForm("quote", CreatedEntityID);
}
Thing is, this opens a new Quote record, but not the revision. It is completely blank, no revision number, no information from the last Quote, and it's not created yet because it's a new form.
When I debug, I see that the CreatedEntityID is null. So that explains it not opening the right thing,
I have referenced :
Any help would be greatly appreciated, this has been driving me crazy all week! BTW we are on Dynamice 365 v9 on premise.
Thanks!






