web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Null reference exception

(0) ShareShare
ReportReport
Posted on by

I run into null reference exception when I execute code activity on server.

protected override void Execute(CodeActivityContext context) {          
        //IWorkflowContext executionContext = context.GetExtension<IWorkflowContext>();
        //IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
        //IOrganizationService service = serviceFactory.CreateOrganizationService(executionContext.UserId);

        //XmlDocument doc = GetEmbeddedXMLDocument();
        //XDocument xDoc = doc.ToXDocument();                       

        ////context.SetValue<bool>(IsExist, false);

        ////string ent = context.GetValue(InputEnt);
        ////string searchAtrib = context.GetValue(SearchAttrib);
        //////string condition = context.GetValue(Condition);
        ////string attribValue = context.GetValue(AttribValue);

        ////QueryByAttribute query = new QueryByAttribute(ent);
        ////query.ColumnSet = new ColumnSet(new String[] {searchAtrib});
        ////query.Attributes.Add(searchAtrib);
        ////query.Values.Add(attribValue);

        ////EntityCollection retrived = service.RetrieveMultiple(query);

        ////if (retrived.Entities.Count>0) {
        ////    context.SetValue<bool>(IsExist, true);
        ////}

        //var docData = new JObject();
        //docData = ParseDataStringToObject(context);            

        //SysColl.List<DataContainer> entityes = new SysColl.List<DataContainer>();
        //FillEntityes(xDoc, entityes);
        //entityes.OrderBy(x => x.Order).ToList<DataContainer>();

        //CreateEntityesInMemo(entityes,docData, service, context);
    }

calling function. Ordinary XMLHttpRequest behind the scene.

var result = Process.callAction("kr_ParseInitialData",
        [{
            key: "InputEnt",
            type: Process.Type.String,
            value: json_object
        }],
        function () {
            //createAttachment(attachmentData);
            debugger
            clearFormControls();
            alert(result);
        },
        function (errInfo) {
            alert(errInfo);
        });

As you can see, I comment everything, but still get the same exception. In Debug code works fine. Any ideas? Sincerely.

*This post is locked for comments

I have the same question (0)
  • Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    Is it possible to download the log?

  • Community Member Profile Picture
    on at

    No. I don't have any logs.

    It seems, that problem occure because dynamic input parameter.

    _1104350437044B043C044F043D043D044B043904_1.png

    
    

    _1104350437044B043C044F043D043D044B043904_1.png

    Maybe something wrong with calling method (JS)?

    Process._callActionBase = function (requestXml, successCallback, errorCallback, url) {
        if (url == null) {
            url = window.parent.Xrm.Page.context.getClientUrl();
        }
    
        var req = new XMLHttpRequest();
        req.open("POST", url + "/XRMServices/2011/Organization.svc/web", true);
        req.setRequestHeader("Accept", "application/xml, text/xml, */*");
        req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");
    
        req.onreadystatechange = function () {
            if (req.readyState == 4) {
                debugger
                if (req.status == 200) {
                    // If there's no successCallback we don't need to check the outputParams
                    if (successCallback) {
                        // Yucky but don't want to risk there being multiple 'Results' nodes or something
                        var resultsNode = req.responseXML.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1]; // <a:Results>
    
                        // Action completed successfully - get output params
                        var responseParams = Process._getChildNodes(resultsNode, "a:KeyValuePairOfstringanyType");
    
                        var outputParams = {};
                        for (i = 0; i < responseParams.length; i++) {
                            var attrNameNode = Process._getChildNode(responseParams[i], "b:key");
                            var attrValueNode = Process._getChildNode(responseParams[i], "b:value");
    
                            var attributeName = Process._getNodeTextValue(attrNameNode);
                            var attributeValue = Process._getValue(attrValueNode);
    
                            // v1.0 - Deprecated method using key/value pair and standard array
                            //outputParams.push({ key: attributeName, value: attributeValue.value });
    
                            // v2.0 - Allows accessing output params directly: outputParams["Target"].attributes["new_fieldname"];
                            outputParams[attributeName] = attributeValue.value;
    
                            /*
                            RETURN TYPES:
                                DateTime = Users local time (JavaScript date)
                                bool = true or false (JavaScript boolean)
                                OptionSet, int, decimal, float, etc = 1 (JavaScript number)
                                guid = string
                                EntityReference = { id: "guid", name: "name", entityType: "account" }
                                Entity = { logicalName: "account", id: "guid", attributes: {}, formattedValues: {} }
                                EntityCollection = [{ logicalName: "account", id: "guid", attributes: {}, formattedValues: {} }]
        
                            Attributes for entity accessed like: entity.attributes["new_fieldname"].value
                            For entityreference: entity.attributes["new_fieldname"].value.id
                            Make sure attributes["new_fieldname"] is not null before using .value
                            Or use the extension method entity.get("new_fieldname") to get the .value
                            Also use entity.formattedValues["new_fieldname"] to get the string value of optionsetvalues, bools, moneys, etc
                            */
                        }
    
                        // Make sure the callback accepts exactly 1 argument - use dynamic function if you want more
                        successCallback(outputParams);
                    }
                }
                else {
                    // Error has occured, action failed
                    if (errorCallback) {
                        var message = null;
                        var traceText = null;
                        try {
                            message = Process._getNodeTextValueNotNull(req.responseXML.getElementsByTagName("Message"));
                            traceText = Process._getNodeTextValueNotNull(req.responseXML.getElementsByTagName("TraceText"));
                        } catch (e) { }
                        if (message == null) { message = "Error executing Action. Check input parameters or contact your CRM Administrator"; }
                        errorCallback(message, traceText);
                    }
                }
            }
        };
    
        req.send(requestXml);
    }


  • Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    I could not understand the language.

    The JS code is correct, if you copied the latest version of Process.js

    You want to invoke the server side code (Workflow Activity) from an Action using JS?

  • Community Member Profile Picture
    on at

    Yes. But my input parameter is a string, parsed Excel file, and it's pretty long. Could it be a problem?

  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Please check whether the workflow is invoked from your JavaScript (by doing some update of a record or so for testing).

    It should accept long string value (I remember using 5 mb). You can also use small string value for testing.

  • Community Member Profile Picture
    on at

    Thank you. It's seems it was a CRM bug. I unregister and reg again same dll, and everything work fine.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans