Good Afternoon,
I am using the CRM REST Builder provided by Jason Lattimer (Thank you for creating this) and I have been able to successfully GET Opportunity Details and the linked Contact (Stackholders). Where I am running into issues is with trying to determine the current StageID an opportunity is on and the Process (Opportunity Sales Process) the opportunity is associated with. Any idea what I need to expand to get that information?
/* Get opportunity details with the associated contacts (connection1, connection2) */
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/opportunities(2b685c81-4f1c-e511-80d3-3863bb347ba8)" +
"?$select=description,stepname,estimatedvalue,opportunityid,statuscode,createdon,modifiedon,name,estimatedclosedate,_ownerid_value" +
"&$expand=opportunity_connections1($select=name,record1objecttypecode,record2objecttypecode,_record2roleid_value,_record2id_value)" +
",opportunity_connections2($select=name,record1objecttypecode,record2objecttypecode,_record2roleid_value,_record2id_value)" +
",parentaccountid($select=accountid)", 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", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
console.clear();
console.log(new Date());
if (this.status === 200) {
var result = JSON.parse(this.response);
console.log('Response: ', result);
console.log('Opportunity Details: ', {
'AccountId': (result.parentaccountid) ? result.parentaccountid.accountid : '',
'Description': (result.description) ? result.description : '',
'StageName': (result.stepname) ? result.stepname.split('-')[1] : '',
'Amount': result.estimatedvalue,
'Id': result.opportunityid,
'IsDeleted': false,
'IsWon': (result.statuscode === 3) ? true : false,
'Type': undefined,
'IsClosed': (result.statuscode === 1) ? false : true,
'CreatedDate': result.createdon,
'SystemModstamp': result.modifiedon,
'Name': result.name,
'CloseDate': result.estimatedclosedate,
'LastModifiedDate': result.modifiedon,
'OwnerId': result._ownerid_value,
'RecordTypeId': result.processid
});
console.log('Opportunity Contacts: ', result['opportunity_connections1']);
} else {
console.log('Error: ', JSON.parse(this.response).error.message);
}
}
};
req.send();








