Skip to main content

I have a custom processing screen with two filter fields.

The filter for the screen id works.  The filter for the file extension does not.

Ignore the first filter field.  I was trying to use a selector to get UploadAllowableFileExtensions, but the value returned includes a “.” in front of the extension.  So I created a DDL with just the last three characters of the extension.  I could not figure a way to trim off the “.” in the value of the selector.

 

When just the screen id is provided, it shows three files for that screen:

 

As soon as I choose PDF from the File Extension2 DDL, the view is refreshed and attempts to apply the file extension filter.  

Here is the code for the applyfilters method:

protected virtual void ApplyFilters(PXSelectBase<UploadFile> shCmd, RecordsToProcessFilter filter)
{

if (filter.ScreenID != null)
shCmd.WhereAnd<Where<UploadFile.primaryScreenID.IsEqual<RecordsToProcessFilter.screenID.FromCurrent>>>();

if (filter.FileExtension2 != null)
{
//returns extansion = 'pdf'
UploadFile test = SelectFrom<UploadFile>.Where<UploadFile.primaryScreenID.IsEqual<@P.AsString>
.And<UploadFile.isSystem.IsEqual<False>>>.View.Select(this, "AM208000").FirstOrDefault();

//returns null
//using FirstOrDefault throws an error so I removed it
UploadFile test2 = SelectFrom<UploadFile>.Where<UploadFile.primaryScreenID.IsEqual<@P.AsString>
.And<UploadFile.extansion.IsEqual<@P.AsString>>
.And<UploadFile.isSystem.IsEqual<False>>>.View.Select(this, "AM208000", "pdf");

shCmd.WhereAnd<Where<UploadFile.extansion.IsEqual<RecordsToProcessFilter.fileExtension2.FromCurrent>>>();
}
}

 

The WhereAnd for the filter.FileExtension2 is intended to only show files from UploadFiles table where the “extansion” =”pdf”.

In debug, I did 2 manual selects to get a record that is being displayed in my grid.  The first select returns a record in the grid and the value in the UploadFile.extansion is “pdf”.  

If I hard code “pdf” in the second test, the record is null.

Note, “extansion” is not a typo in the code.  That is the DAC field name.  

Obviously, if my test2 select returns null, the whereand is going to cause a null result set.

To prove that the value for extansion in test1 is pdf, here is a screen shot:

The FileExtension2 value in my Filter is also “pdf”

test2 returns null:

The real issue is why can’t I return a record in test2?  If I can resolve that, the filter will probably work just fine.

Now that I have submitted this, I will probably figure it out in the next 3 minutes.  😏

 

 


//returns null
//using FirstOrDefault throws an error so I removed it
UploadFile test2 = SelectFrom<UploadFile>.Where<UploadFile.primaryScreenID.IsEqual<@P.AsString>
.And<UploadFile.extansion.IsEqual<@P.AsString>>
.And<UploadFile.isSystem.IsEqual<False>>>.View.Select(this, "AM208000", "pdf");

 

What was the error?


Can you post the DAC?


Here is where the error takes me:

 

This is the error that is presented on the screen.

 

 

Here is the Filter DAC.  This project started from a copy of another project I did.  The only two fields being used are the ScreenID and FileExtension2.  FilteExtension is a Selector which I’m not using because the value of the field starts with a “.” and that screws up the comparison with the value in the UploadFile DAC.

        oSerializable]
rPXCacheName("Filter")]
public class RecordsToProcessFilter : PXBqlTable, IBqlTable
{
#region ScreenID
PXString(8, IsFixed = true)]
PXDefault("AM208000", PersistingCheck = PXPersistingCheck.Nothing)]
PXUIField(DisplayName = "Screen ID")]
PXSelector(typeof(Search<SiteMap.screenID>),
typeof(SiteMap.screenID),
typeof(SiteMap.title))]
public virtual string ScreenID { get; set; }
public abstract class screenID : PX.Data.BQL.BqlString.Field<screenID> { }
#endregion

#region FileExtension
PXString(255, IsUnicode = true)]
PXUIField(DisplayName = "File Extension")]
PXSelector(typeof(Search<UploadAllowedFileTypes.fileExt>))]
public virtual string FileExtension { get; set; }
public abstract class fileExtension : PX.Data.BQL.BqlString.Field<fileExtension> { }
#endregion

#region FileExtension2
PXString(3, IsFixed = true)]
PXUIField(DisplayName = "File Extension2")]
// PXDefault("PDF", PersistingCheck = PXPersistingCheck.Nothing)]
PXStringList(
new string ]
{
"pdf",
"jpg",
"png"
},
new string ]
{
"PDF",
"JPG",
"PNG"
})]

public virtual string FileExtension2 { get; set; }
public abstract class fileExtension2 : PX.Data.BQL.BqlString.Field<fileExtension2> { }
#endregion
}
}

If it would help, I can make a zip file of my VS project.  The code is in horrible shape as it is a copy of another processing screen I did in the past and is just a starting point for proof of concept on this project.  Lots of commented out code etc.  Hopefully the filter DAC will point out something obvious.  However, the DAC actually has nothing to do with the error that occurs when debugging test2.  It doesn’t even reference it.  It seems like there is some underlying issue with the UploadFile DAC.

Just for kicks and a huge waste of time, I’m going to create a SQL View and use that instead of the UploadFile DAC.  I bet I don’t have a problem.


Friends, I just noticed something when I was creating a SQL View for the UploadFile table.  The field name “extansion” in the DAC is not a real field in the UploadFile table.  I am thinking this has something to do with this issue. 

I don’t see anywhere in the tables where the file extension is stored separately.  I’m going to use the SQL View to get just the extension from the file name and return it as a field.  I don’t know how Acumatica gets the “extansion” field values in their DAC but I’m guessing they are simply getting the last characters of the file name after the last occurrence of the period.

In my join from UploadFile to my SQL View, I can get the extension.

I’ll report back if this works.  

I don’t want to have to do a workaround, but I will if I can’t get the above issue resolved.


This returns a value now:

                UploadFile test2 = SelectFrom<UploadFile>.InnerJoin<ICSUploadFileView>.On<ICSUploadFileView.fileID.IsEqual<UploadFile.fileID>>
                    .Where<UploadFile.primaryScreenID.IsEqual<RecordsToProcessFilter.screenID.FromCurrent>
                    .And<ICSUploadFileView.fileExtension.IsEqual<RecordsToProcessFilter.fileExtension.FromCurrent>>>
                    .View.Select(this).FirstOrDefault();

It is joining to a simple SQL View

CREATE OR ALTER VIEW ICSUploadFileView
AS
    SELECT
        CompanyID,
        FileID,
        RIGHT(aName], 4) AS FileExtension
    FROM
        dbo.UploadFile
GO

 

If someone knows a way to get the right 4 characters from the field Name from UploadFile as part of the whereAnd clause, that would solve the issue.  

I don’t think I can use a function such as IndexOf etc. within the whereand clause.


I did a quick search and found that there is a Substring function with in BQL. So then I searched for .Substring< and found a handful of instances were it is used in the supplied ACM code.

ARInvoiceEntry has this in a PXDefault but it should show you how to do what you need.

[PXDefault(typeof(Where2<FeatureInstalled<FeaturesSet.paymentsByLines>,
And<ARInvoice.origModule, NotEqual<BatchModule.moduleTX>,
And<ARInvoice.origModule, NotEqual<BatchModule.moduleEP>,
And<ARInvoice.origModule, NotEqual<BatchModule.moduleSO>,
And<Data.Substring<ARInvoice.createdByScreenID, int0, int2>, NotEqual<BatchModule.moduleFS>,
And<ARInvoice.isMigratedRecord, NotEqual<True>,
And<ARInvoice.pendingPPD, NotEqual<True>,
And<Current<Customer.paymentsByLinesAllowed>, Equal<True>>>>>>>>>))]

You’ll need to create a quick class for int4 but, otherwise, that should give you what you’re looking for.


@Django in my original code above, I did a test select where I hard coded pdf.

UploadFile test2 = SelectFrom<UploadFile>.Where<UploadFile.primaryScreenID.IsEqual<@P.AsString> .And<UploadFile.extansion.IsEqual<@P.AsString>> .And<UploadFile.isSystem.IsEqual<False>>>.View.Select(this, "AM208000", "pdf");

This returns a null.  This is the root issue for me.  The value that shows for “Extansion” in the debug screen is pdf (no period).  So this select statement should return a value.  If this statement returned a value, then I could pursue the substring.  Since it fails, it wouldn’t matter even if I could use substring.  

The only think I can think of is that there is some embedded character in the value of the Extansion field which causes the match to pdf to fail.  

I’ve given up and I am using a SQL view to get the full extension (“.pdf”) and then comparing that to the value in my filter selector.  If you can find a way to figure out how to get that select statement to return a record, that would be the trick.


@Joe Schmucker  Have you considered coding a delegate for your processing view and using the filter values to limit the data via LINQ?  https://help.acumatica.com/Help?ScreenId=ShowWiki&pageid=a5fc2e9a-16c1-4486-abb3-216100466b37


I’m curious to know if running a SQL trace would help to figure out why your statement didn’t work.


Thanks for the ideas guys.  I’m about to leave for the day, but I will dig into your ideas and let you know what I find.  

THANKS for taking the time to help me out!


Reply