Search code examples
javascriptdynamics-crmcustom-actiondynamics-crm-webapicustom-activity

CRM custom activity do not return output argument


I have written a custom activity as below,

namespace Tu.Crm.Packages.WorkFlows
{
    public sealed class VersionFinder : CodeActivity
    {
        [Output("VersionDate")]
        public OutArgument<string> VersionDate { get; set; }

        protected override void Execute(CodeActivityContext executionContext)
        {
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
           
            try
            {
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                VersionDate.Set(executionContext, "1#22/01/2019");
                
            }
            catch (FaultException<OrganizationServiceFault> e)
            {
                // Handle the exception.
                throw new InvalidPluginExecutionException("Some error occurred/Proxy service unreachable" + e.StackTrace);
            }
        }
    }
}

I am trying to call this activity from JavaScript.

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/new_versionfinderc2dcf0b12782eb11814500155de400c4", false);
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 === 204) {
            Xrm.Utility.alertDialog(this.ResponseXML);
        } else {
            Xrm.Utility.alertDialog(this.ResponseXML);
        }
    }
};
req.send();

However, it is not returning any data. What could be wrong?


Solution

  • I never tried calling custom workflow activity directly in js using web api, and its not usual to do AFAIK. The recommended way is to convert this into a custom action and call it in js web api.

    If you want to keep this CWA, then use it in an UI workflow and execute the WF from js web api. You can use CWA in custom action too.