I'm working on Dynamics CRM 365, trying to apply a logic using javascript on the opportunity form.
The need is to change a field's value and save the form before another treatment could refresh it.
var opportunityID= formContext.data.entity.getId();
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
" <entity name='saft_bpf_isd_opportunities'>"+
" <attribute name='businessprocessflowinstanceid' />"+
" <attribute name='activestageid' />"+
" <filter type='and'>"+
" <condition attribute='bpf_opportunityid' operator='eq' uitype='opportunity' value='"+opportunityID+"' />"+
" </filter>"+
" </entity>"+
"</fetch>";
Xrm.WebApi.retrieveMultipleRecords("saft_bpf_isd_opportunities","fetchXml= " + fetchXml).then(
function success(result) {
debugger;
alert("existed value ==> "+formContext.getAttribute("saft_activestage").getValue());
alert("new value ==> "+result.entities[0]._activestageid_value);
formContext.getAttribute("saft_activestage").setValue(result.entities[0]._activestageid_value);
formContext.data.save(70).then(function (result) {});
},function(error) {
console.log(error.message);
}
);
// the reatement refreshing the form
formContext.data.process.setActiveProcess(idProcess_ISD, function (result) {});
But when I apply this code, I can simlply display the value but not assign it to the field desired.
formContext.data.process.setActive(...)
into theSuccess
method? – jasonscript