I need to auto-increment my Quote Products if Criteria x is met. I found this thread https://community.dynamics.com/crm/f/117/t/107623 with some JavaScript by Jason Lattimer. I am new to JavaScript:
1. The thread was dated 2013 - will these properties & methods work for 2016 Online CRM?
2. Do I need to change SalesOrderDetailSet to QuoteProduct?
3. I set an alert after the initial IF statement, but I'm not reaching it. What needs to be changed?
This is the JavaScript I used:
function Form_OnLoad() {
if (Xrm.Page.ui.getFormType() != 1) {
return;
}
alert("Yes!");
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/SalesOrderDetailSet?$select=LineItemNumber&$top=1&$orderby=LineItemNumber desc&$filter=SalesOrderId/Id eq guid'" + Xrm.Page.context.getQueryStringParameters()["_CreateFromId"] + "'";
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", oDataSelect, false);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
retrieveReq.onreadystatechange = function () {
GetData(this);
};
retrieveReq.send();
}
function GetData(retrieveReq) {
if (retrieveReq.readyState == 4) {
if (retrieveReq.status == 200) {
var retrieved = JSON.parse(retrieveReq.responseText).d;
if (retrieved.results[0] != null) {
Xrm.Page.getAttribute("lineitemnumber").setValue(parseInt(retrieved.results[0].LineItemNumber) + 1);
} else {
Xrm.Page.getAttribute("lineitemnumber").setValue(1);
}
}
}
}
*This post is locked for comments