SaaS News Hubb
Advertisement
  • Home
  • News
  • Software Engineering
  • Software Development
  • SAAS Applications
  • Contact Us
No Result
View All Result
  • Home
  • News
  • Software Engineering
  • Software Development
  • SAAS Applications
  • Contact Us
No Result
View All Result
SaaS News Hubb
Home SAAS Applications

NullReferenceException Thrown using Organization Service RetrieveMultiple Method

by admin
May 6, 2022
in SAAS Applications
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


My company uses Field Service and I have a single webpage our company uses to allow 3rd Party contractors to accept or decline work order assignments. No changes have been made to our processes or to the code for this app, but yesterday we began getting errors on the webpage. 

The error is that an “Object reference not set to an instance of an object.” The thing is I’m having trouble finding any null objects where this error is being thrown.

On Page_Load I have a method that instantiates a private IOrganizationService variable. This method executes successfully and returns a connection. I updated this method a few months ago when WS-TRUST was deprecated and it seems to have been working with no issues:

public IOrganizationService GetOrganizationService()
{
    string serverUrl = ConfigurationManager.AppSettings["ServerUrl"];
    string userName = ConfigurationManager.AppSettings["UserName"];
    string password = ConfigurationManager.AppSettings["Password"];
    string errorMsg = String.Empty;
    try
    {
        ClientCredentials clientCredentials = new ClientCredentials();
        clientCredentials.UserName.UserName = userName;
        clientCredentials.UserName.Password = password;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        this.organizationService = new CrmServiceClient("AuthType=OAuth;Username=CREDUSER;Password=CREDPWD;Url=ORGURL;AppId=AZUREAPPID;RedirectUri=AZUREREDIRECTURI;LoginPrompt=Auto");
    }
    catch (Exception exception)
    {
        errorMsg = exception.Message;
    }

    return this.organizationService;
}

Then, based on a querystring variable in the URL there is a lookup to retrieve the Work Order record in CE:

public void RetrieveWorkOrder()
{
    if (base.Request.QueryString["workorder"] != null)
    {
        string QEmsdyn_workorder_msdyn_name = Convert.ToString(base.Request.QueryString["workorder"]).Trim();
        this.hdn_workOrderNumber.Value = QEmsdyn_workorder_msdyn_name;
        QueryExpression QEmsdyn_workorder = new QueryExpression("msdyn_workorder");
        QEmsdyn_workorder.ColumnSet.AddColumns(new string[] { "dxc_primarytechnician", "dxc_backuptechnician", "msdyn_name", "createdon", "dxc_scheduledbooking", "dxc_assignedtechnician", "msdyn_substatus" });
        QEmsdyn_workorder.Criteria.AddCondition("msdyn_name", 0, new object[] { QEmsdyn_workorder_msdyn_name });

        // debugging NullReferenceException
        string msg = String.Empty;
        if (Object.ReferenceEquals(QEmsdyn_workorder, null))
        {
             msg = "QEmsdyn_workorder is null";
        }
        if (Object.ReferenceEquals(this.organizationService, null))
        {
            msg = "organizationService is null";
        }
        if (Object.ReferenceEquals(QEmsdyn_workorder_msdyn_name, null))
        {
            msg = "QEmsdyn_workorder_msdyn_name is null";
        }

        // try calling a method of organizationservice just as an extra step
        msg = this.organizationService.ToString();
        // end debuggin

        EntityCollection workOrderCollection = this.organizationService.RetrieveMultiple(QEmsdyn_workorder); // <--- ERROR THROWN HERE

        if (workOrderCollection.Entities.Count > 0)
        {
            this.workOrderEntity = workOrderCollection.Entities[0];
            this.hdn_workOrderCreatedOn.Value = Convert.ToString(this.workOrderEntity["createdon"]);
            this.hdn_scheduledBooking.Value = Convert.ToString(this.workOrderEntity["dxc_scheduledbooking"]);
            this.hdn_assignedTechnician.Value = Convert.ToString(((OptionSetValue)this.workOrderEntity["dxc_assignedtechnician"]).Value);
        }
    }
}

The organizationService object is not null, the QEmsdyn_workorder QueryExpression object is not null, the ColumnSet and Criteria members of the QueryExpression are not null, yet this line continues to produce the error:

EntityCollection workOrderCollection = this.organizationService.RetrieveMultiple(QEmsdyn_workorder);

I’ve also checked the ColumnSet values just to make sure they are correct, although in my head I know they are correct and also again this has been working for over a year with the only change being to change authentication when WS-TRUST was deprecated a few months ago. But even after that change this app has been used daily for months with no issues. 

I’m feel like I’ve hit a wall with this for the moment so wanted to reach out to see if anyone else has any ideas or are experiencing a similar issue. The answer may be right in front of my eyes but I’ve looked at this long enough that I can’t see it.



Source link

Previous Post

How to Compare Manufacturing ERP vs. Generic ERP Systems

Next Post

Cognizance of Blockchain Security Implications

Related Posts

SAAS Applications

Forum Post: Auditing feature

May 15, 2022
SAAS Applications

CRM reporting Extension – SSRS instance is blank

May 14, 2022
SAAS Applications

Greenshades Selects Branch as Exclusive Banking and Card Solution

May 14, 2022
SAAS Applications

Developer Community: By Helping Others We Help Ourselves

May 14, 2022
SAAS Applications

Reach New Heights and Fuel Growth with Sugar

May 13, 2022
SAAS Applications

Web Service No Longer Able to Connect to Dynamics CRM

May 13, 2022

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Popular

Software Engineering

Snyk Engineering with Guy Podjarny

May 15, 2022
Software Development

What “The Great British Baking Show” teaches us about teamwork in software development

May 15, 2022
SAAS Applications

Forum Post: Auditing feature

May 15, 2022
Software Engineering

Software is adopted, not sold (Ep. 441)

May 14, 2022
Software Engineering

Data Delivery with Naqeeb Memon

May 14, 2022
Software Development

Ping vs Traceroute: How to Troubleshoot Your Connections

May 14, 2022
Software Development

10 Free Portfolio & Lookbook Templates for Adobe InDesign

May 14, 2022
SAAS Applications

CRM reporting Extension – SSRS instance is blank

May 14, 2022
SAAS Applications

Greenshades Selects Branch as Exclusive Banking and Card Solution

May 14, 2022

© 2022 Sass News Hubb All rights reserved.

Use of these names, logos, and brands does not imply endorsement unless specified. By using this site, you agree to the Privacy Policy

Navigate Site

  • Home
  • News
  • Software Engineering
  • Software Development
  • SAAS Applications
  • Contact Us

Newsletter Sign Up

No Result
View All Result
  • Home
  • News
  • Software Engineering
  • Software Development
  • SAAS Applications
  • Contact Us