Hi all,
Hoping I can get some advice with this, having an issue since we've switched our test environment to force UCI. I had a JS script which was working perfectly beforehand which is supposed to pop up and ask the user if they want to schedule another home visit (a custom activity entity in our solution) on marking an existing one complete. It then opens the Quick Create form for the entity and prefills some fields. Then a workflow is created & run to mark the current record as completed.
All of these steps still happen in the new environment but the issue is we now get 2 error pop ups, with codes 0x83215605 (opens as soon as initial record is marked complete) and 0x83215603 (opens when 'Yes' is clicked in the dialog box). Are there any known issues with the Unified Interface affecting scripts in this way? I have searched online but couldn't find anything. Alternatively if there's something amiss in my script I'm more than happy to be corrected! I've pasted my code below and would really appreciate any input or advice. Thanks!
function onSave(executionContext) { var formContext = executionContext.getFormContext(); var thisEntityID = formContext.data.entity.getId(); var entityID = thisEntityID.slice(1, -1); var eventArgs = executionContext.getEventArgs(); var saveMode = eventArgs.getSaveMode(); if (saveMode === 58) { //Mark as complete eventArgs.preventDefault(); var confirmStrings = { text:"Do you want to book in the next home visit for this carer? (Recommended)", title:"Schedule Next Visit?", cancelButtonLabel:"No", confirmButtonLabel:"Yes" }; var confirmOptions = { height: 200, width: 450 }; Xrm.Navigation.openConfirmDialog(confirmStrings,confirmOptions).then(function (success) { if (success.confirmed) scheduleNext(formContext, entityID); formContext.data.save(); }); } else {statusComplete(entityID);} } function scheduleNext(formContext, entityID){ formContext.data.save(); var entityFormOptions = {}; entityFormOptions['entityName'] = 'mfs_homevisit'; entityFormOptions['useQuickCreateForm'] = true; var formParameters = {}; formParameters['mfs_carer'] = formContext.getAttribute('mfs_carer').getValue()[0].id; formParameters['mfs_carername'] = formContext.getAttribute('mfs_carer').getValue()[0].name; formParameters['subject'] = 'Test Subject'; Xrm.Navigation.openForm(entityFormOptions, formParameters).then( function (success) { console.log(success); }, function (error) { console.log(error); }); statusComplete(entityID); } function statusComplete(entityID){ var entity = { "EntityId": entityID //entity ID passed in in function call }; //alert(JSON.stringify(entity)); var WorkflowId = "1B4F8530-D9E7-47F1-BE35-B12DB2068832"; //change status to complete workflow ID var gc = Xrm.Utility.getGlobalContext(); var req = new XMLHttpRequest(); req.open("POST", gc.getClientUrl() + "/api/data/v9.0/workflows(" + WorkflowId + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow", 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.onreadystatechange = function() { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { console.log("Success"); } else { console.log(JSON.parse(this.response).error); } } }; req.send(JSON.stringify(entity)); }