CompanyInfoProvider.GetCompanyInfo always return null

Ashutosh Pandey asked on February 21, 2019 19:26

I created a cms module and added class named Company (namespace = Tech)

I have a UniGrid control like this:

<cms:UniGrid ID="companyGrid" runat="server" ObjectType="Tech.Company">
    <GridActions Parameters="CompanyID">
        <ug:Action Name="edit" Caption="$General.Edit$" FontIconClass="icon-edit" FontIconStyle="allow" CommandArgument="CompanyGuid" />
        <ug:Action Name="#delete" Caption="$General.Delete$" FontIconClass="icon-bin" FontIconStyle="critical" Confirmation="$General.ConfirmDelete$" />
        <ug:Column Source="CompanyName" Caption="Company Name" Localize="true" runat="server">
            <Filter Type="Text" Size="256" />
        <ug:Column Source="State" Caption="State" Localize="true" runat="server">
            <Filter Type="Text" Size="256" />
        <ug:Column Source="Country" Caption="Country" Localize="true" runat="server">
            <Filter Type="Text" Size="256" />
        <ug:Column Source="WebsiteURL" Caption="Website URL" Localize="true" runat="server">
            <Filter Type="Text" Size="256" />
    <GridOptions DisplayFilter="true" />

There is my OnAction code:

protected void companyGrid_OnAction(string actionName, object actionArgument)
    string guid = ValidationHelper.GetString(actionArgument, string.Empty);

    if (actionName == "edit")
        Response.Redirect("~/CMSModules/Tech/Companies/Edit.aspx?guid=" + guid);

I am trying to find a record in table using following lines:

    string guid = Request.QueryString["id"];
        //companyInfo = CompanyInfoProvider.GetCompanyInfo(new Guid(guid));
        companyInfo = CompanyInfoProvider.GetCompanyInfo(ValidationHelper.GetGuid(guid, Guid.NewGuid()));

    catch (Exception ex)
        lblMessage.Text = ">> " + (companyInfo == null);

The value of guid I get is: 098f8ef1-64fc-427d-91a5-1ec2e2da131f

I always get >> True in my label, means companyInfo is always null.

If I try to execute manual query, it finds the record.

While generating the code files, I tried all possibilities:

Guid Column => CompanyGuid

Display name column => CompanyGuid

Code name column => CompanyGuid

What am I doing wrong?

Recent Answers

Brenden Kehren answered on February 21, 2019 19:39

Is your variable guid already a type of guid? If so, no need to cast it to a guid. In fact, you should probably use something like:

var companyInfo = CompanyInfoProvider.GetCompanyInfo(ValidationHelper.GetGuid(guid, Guid.NewGuid());

0 votesVote for this answer Mark as a Correct answer

Ashutosh Pandey answered on February 22, 2019 08:27

Hi Brenden, thanks for the quick reply. I updated my question and tried your suggestion. I also provided more insights on my problem. I am still getting companyInfo as null :(

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 22, 2019 15:01

Does your CompanyInfoProvider have a method to get a company by a GUID? If not then that's your problem. You need to either create one or use

var company = CompanyInfoProvider.GetCompanies().WhereEquals("CompanyGuid", ValidationHelper.GetGuid(guid, Guid.NewGuid())).FirstObject;

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.