Skip to main content
Answer

How to get Tenant Status of the Tenant Screen SM203520

  • February 9, 2025
  • 4 replies
  • 80 views

aaghaei
Captain II
Forum|alt.badge.img+10

Hello all,

 

Does anyone know how I can get the Status of a tenant via code (below screenshot)? Is there any service for it? I tried the below but no luck

CompanyMaint companyMaint = PXGraph.CreateInstance<CompanyMaint>();
UPCompany upCompany = UPCompany.PK.Find(companyMaint, PXAccess.GetParentOrganizationID(companyMaint.Accessinfo.BranchID), PKFindOptions.None);

 

 

Best answer by aaghaei

Thank you ​@Nilkanth Dipak and ​@smuddurthi81 

LicensingManager is an internal class and when I try to use it get an error that is not accessible due to its protection level.

I had tried originally performing Select() or PK.Find() on UPCompany but not sure platform raises an error like UPCompany is not a DAC. It is the first time I see such a thing.

What I ended up doing and works (not clean though) is to first perform .Search<> on CompanyMaint.Companies<UPCompany.status> view then manually RaiseFieldSelecting<UPCompany.status> to evaluate the field and get the correct value.

 

4 replies

Forum|alt.badge.img
  • Varsity I
  • February 10, 2025

@aaghaei Can you please try this.

The UI status (e.g., "Test Tenant", "Production", etc.) is determined by the UPCompany.InstanceType and potentially other configurations related to licensing and setup. It's not a single field.

using PX.SM; // For UPCompany
using PX.CS; // For CompanyMaint
using PX.Data;

// ... other code ...

CompanyMaint companyMaint = PXGraph.CreateInstance<CompanyMaint>();
Guid parentOrganizationID = PXAccess.GetParentOrganizationID(companyMaint.Accessinfo.BranchID);
UPCompany upCompany = UPCompany.PK.Find(companyMaint, parentOrganizationID, PKFindOptions.None);

if (upCompany != null)
{
    string status = GetTenantStatus(upCompany);
    // Use the 'status' variable as needed (e.g., display in a grid, log, etc.)
    PXTrace.WriteInformation($"Tenant Status: {status}"); 
}
else
{
    PXTrace.WriteWarning($"UPCompany record not found for ID: {parentOrganizationID}");
}

// Helper function to determine the status
private string GetTenantStatus(UPCompany company)
{
    if (company.InstanceType == "T") // Assuming "T" represents Test Tenant
    {
        return "Test Tenant";
    }
    else if (company.InstanceType == "P") // Assuming "P" represents Production
    {
        return "Production";
    }
    else if (company.InstanceType == "D") // Assuming "D" represents Demo
    {
        return "Demo Tenant";
    }
    // Add more conditions as needed for other InstanceType values

    // Default case or handle unknown types
    return "Unknown"; 
}


DipakNilkanth
Pro III
Forum|alt.badge.img+13

Hi ​@aaghaei,

Have you tried with creating the graph instance of the PXLicense graph to get the tenant status?

I researched bit and found the status code from base code and it is retrieving like below.
 

I believe,  below code will helps you to get the status of tenant.
 

public string GetTenantStatus(string tenantName)
{
PXLicense license = LicensingManager.Instance.License;

if (!license.Licensed)
{
return "Trial"; // Unlicensed state
}

if (license.Trials != null && license.Trials.Contains(tenantName))
{
return "Trial"; // The tenant is in a trial period
}

if (PXDatabase.AvailableCompanies.Contains(tenantName))
{
return "Active"; // Tenant is active and licensed
}

if (PXDatabase.Companies == null || PXDatabase.Companies.Length == 0)
{
return "Active"; // Defaulting to Active if no explicit status is found
}

return "Unlicensed"; // If none of the above conditions match
}
string tenantName = PXAccess.GetCompanyName();
string status = GetTenantStatus(tenantName);

Hope, it helps!


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • Answer
  • February 11, 2025

Thank you ​@Nilkanth Dipak and ​@smuddurthi81 

LicensingManager is an internal class and when I try to use it get an error that is not accessible due to its protection level.

I had tried originally performing Select() or PK.Find() on UPCompany but not sure platform raises an error like UPCompany is not a DAC. It is the first time I see such a thing.

What I ended up doing and works (not clean though) is to first perform .Search<> on CompanyMaint.Companies<UPCompany.status> view then manually RaiseFieldSelecting<UPCompany.status> to evaluate the field and get the correct value.

 


DipakNilkanth
Pro III
Forum|alt.badge.img+13

@aaghaei,

Thanks for your feedback. yes, I have not implemented LicensingManager  earlier, i just got reference in code, So I suggested.

Thanks for sharing your findings.