Override a Dataview in acumatica - acumatica

I would like to override the bql query which is present in the appaymentlist dataview. shown in the screen shot below.
when i try to override appaymentlist in graph extension, I am unable to implement if() statement because of private "Cleared" field defined in the base graph.
My question are
How do I implement if() condition statement in the PXOverride dataview.
If I omit if() condition in pxoverride , will the base appaymentlist() implement if() condition statements. I mean , will the override "appamentlist" merges with the base "appaymentlist()"
What is the best way to override to implement such scenario?
any suggestions would be helpful.

You can't override a private field so what you need to do is:
Locate every location where the private field is used.
Copy paste/override all these location in your customization.
Sometimes these locations can be private too. In that case you need to find every location that calls into private elements and replace them.

Related

Pull Attributes from Stock Item to SO Line custom field

I'm relatively new to customization programming in Acumatica and I have a question about the best way to pull in attribute values from the stock item screen to a custom field on the SO Line in the sales order screen.
I have done something similar on another screen using a FieldSelecting event and a PXSelect statement to pull data from another screen and update my custom field.
Needing to pull the values from the attribute value is what's stumping me, should I just join to the CSAnswers table in the pxselect?
I also wanted to ask if there is a better overall approach for pulling data from another screen into a custom field in an Acumatica customization.
*update *
I'm attempting to use the PXDBScalar attribute, but I cannot figure out how to join multiple tables. Here's what I've tried.
[PXDBScalar(typeof(
Search2<CSAnswers.value,
InnerJoin<InventoryItem,
On<SOLine.inventoryID, Equal<InventoryItem.inventoryID>>>,
InnerJoin<CSAnswers,
On<InventoryItem.noteID, Equal<CSAnswers.refNoteID>>>,
Where<CSAnswers.attributeID, Like<QHOLDAttr>>
>))]
Thanks
Scott
Since you asked for "a better overall approach" then I'll share my preferred way of handling this. Not to say it is "better" but perhaps just "different".
I try to keep my data tied to the object where it is related directly. In the case of an attribute of an InventoryItem, I would elevate that attribute value to InventoryItem in a DAC extension so that it can be leveraged anywhere the InventoryItem is used. You seem to want to use it in conjunction with the SOLine record, but since the attribute is not tied to the SOLine, I would not extend SOLine to add it. There is nothing wrong with adding it there if your business requirement mandates it, but it keeps me more sane to know that an InventoryItem's related data comes from InventoryItem rather than trying to remember where I put it and possibly duplicate the effort elsewhere (like on a POLine) later.
Here is an example of how I've done it, pulled straight from my project but changing the Attribute references to be more generic.
public sealed class InventoryItemExt : PXCacheExtension<PX.Objects.IN.InventoryItem>
{
#region MyAttribute
[PXString]
[PXUIField(DisplayName = Messages.MyAttribDisplayName)]
[PXDBScalar(typeof(Search<CSAnswers.value,
Where<CSAnswers.refNoteID, Equal<InventoryItem.noteID>,
And<CSAnswers.attributeID, Equal<MyAttribute>>>>))]
public string MyAttribute { get; set; }
public abstract class myAttribute : PX.Data.BQL.BqlString.Field<myAttribute> { }
#endregion
public class MyAttribute : PX.Data.BQL.BqlString.Constant<MyAttribute>
{
public MyAttribute() : base("MYATTRIB") { }
}
}
Notice the constant defined to access the AttributeID "MYATTRIB" which is attached to the Item Class of the InventoryItem record.
Now that the attribute is pulled into the DAC extension on InventoryItem, I can use it on any screen related to an InventoryItem with ease as long as InventoryItem (and the associated DAC extension) have been made available to that screen.
Without testing, I may be off on this but with regards to your attempt to join 2 tables in the PXDBScalar...
When you say Search2<CSAnswers.value..., you have indicated that you want to search the CSAnswers DAC and retrieve the value field. By subsequently trying to InnerJoin back to CSAnswers, I believe you effectively have said:
Select CSAnswers.Value From CSAnswers
Inner Join InventoryItem On SOLine.InventoryID = InventoryItem.InventoryID
Inner Join CSAnswers...
I'm not sure if the SOLine reference is valid here, but it may be if you are defining this directly in the SOLine DAC extension. However, you have tried to query CSAnswers Inner Join CSAnswers. Not sure if this will fix your PXDBScalar, but if you really want to use your method to attach this to SOLine, try:
Search2<CSAnswers.value,
InnerJoin<InventoryItem,
On<InventoryItem.inventoryID, Equal<SOLine.inventoryID>>>,
Where<InventoryItem.noteID, Equal<CSAnswers.refNoteID>,
And<CSAnswers.attributeID, Equal<QHOLDAttr>>>
>))]
(Notice that I swapped the order of the relations in On clauses.)

Purpose of AssertRequiredRoles?

I am implementing my own RequiredRole attribute called RequiredAnyRole, whereby I pass in a list but the user only has to be in 1 of the roles. I have implemented my own method called HasAnyRole which simply queries based on .Any() instead of .All().
I have then overridden the Execute method to use my method rather than HasAllRoles. The problem is im not sure what the method: AssertRequiredRoles is doing? It doesn't seem to be called?
Should I override that to use .Any() rather then .All() too? Here is the original code:
https://github.com/ServiceStack/ServiceStack/blob/82241fc96e187d12f9db2556aea37cf327813adc/src/ServiceStack.ServiceInterface/RequiredRoleAttribute.cs
AssertRequiredRoles is a static helper method that's can be used by other plugins like RequestLogsService to ensure access is only granted to users with the required roles. It's not called when used as a normal attribute filter.
Once you override Execute you retain full control of what gets executed, so you only need to override what you need.

Custom field type to replace MultiLookup in Sharepoint 2010. Where to inherit from?

I am developing a custom field type which should look like a MultiLookup (two Listboxes, "add" and "remove" - Buttons). But I do not want to save that data in the List that contains the field. In other words: There should be happening completely custom code.
I have an idea how to solve it, but am unsure of what type I should derive my custom control from. Or doesn't this matter when I override FieldRenderingControl and I can just use
public class MyCustomField:SPFieldText
?
It doesn't matter as long as you don't save data in the list. Choose the one with the smallest footprint, boolean or so (I don't exactly know the name).

How can I tell ReSharper to stop creating readonly fields?

This question is similar, but my question seems to get asked in an unanswered comment.
I create a C# class. I use alt-insert to add a constructor. I add an argument to the constructor, and then I use alt-enter to create and initialize a field from that argument, like so:
The problem is that my field gets created as a readonly field, and in many cases I do not want to create a readonly field.
readonly int my_int;
How can I tell ReSharper not to add make my field readonly? I've tried to do a pretty thorough search in the ReSharper options, but apparently I'm missing something!
I too cannot find any option to change the creation default; however, if you allow R# to create this field as it likes (ie readonly), and later type this:
public void Bar(int baz)
{
my_int = baz;
}
then the assignment to my_int will get a red squiggly underline, since it is illegal, and the offered quick fix (Alt+Enter) at that location will be Make field 'my_int' non-readonly.
So in the spirit of 'code first', you might want to just let R# do its thing, and also use it to change it as and when you actually need it changed (which might of course turn out to be never...)
The field creation is hardcoded to be readonly on creation. The idea is that you're creating a field, so it doesn't have any usages to default to the most restrictive, if you try to write to it elsewhere, you can alt+enter at that point and remove the readonly status. If the field already exists, ReSharper will try and initialise the existing field from the parameter.
If you want to, you can write a plugin to generate the field as non-readonly. You should look at the IntroduceFieldFix class in dotPeek. It's got several constructors, which binds the quick fix to the warning squigglies, and it will introduce a field using the default pattern for the current language (which is hardcoded to "private readonly $0 $1;")
You can create a class that also derives from InitializeFieldFix, and includes a constructor that takes UnusedParameterWarningBase as a parameter. You can then follow the same implementation as IntroduceFieldFix, but provide a different pattern for the field creation, checking for the current language first.
Another option may be to use 'Introduce Field' refactoring instead. The best way to call it is to use 'Refactor This' (Ctrl+Shift+R) on a parameter declaration and choose 'Introduce Field' from the reduced number of refactoring options. By default it will generate writable field but there is also an option to change modifiers.

SPGridView, data and correct method of ensuring data is safe

I am using an SPGridView to present some data, and have enabled the filtering ability which works very well. Until you choose a particular item in the data to filter on...
The data item in question has an apostrophe in the string( e.g. "this is richards' string"), which causes the post-filter-application page load to die with the error:
Syntax error: Missing operand after 's' operator.
Obviously the data is not automatically made safe...
The data is in a datatable, and the SPGridView is fed using an objectdatasource using the datatable.
Whats the best, or correct, method to ensure the data is safe to use?
EDIT:
After much gnashing, I have found a partial answer but the question still remains.
The partial answer is - you can make the data safe for the filter code, but you then cannot make it look correct in the filter dropdown gui.
Adding BoundField.HtmlEncode = true; to the SPGridView definition does nothing.
Using HttpUtility.HtmlEncode on the string does nothing.
Manually replacing all apostrophes in the data with ampersand #39; on insertion into the DataTable allows the filter to work fine, and the data displays fine in the SPGridView, but it displays with the html replacement string in the filter dropdown, and not the apostrophe character. This is the partial solution, and isn't really usable as it creates a horrible filter string which is visible to the end user.
I am still to find a complete solution to this problem, save for removing offending characters from the data altogether, which isn't really a solution.
Regards
Richard
The apostrophe is a special character in the filters. Try replacing all instances of the "'" (one apostrophe) with "''" (double apostrophe).
Edit 09/01/2009
Ok, so it took me a lot longer than I thought to actually get this working. You should just need to add this to your web part code:
protected override void OnPreRender(EventArgs e)
{
if (!string.IsNullOrEmpty(gridDS.FilterExpression))
{
_gridDS.FilterExpression = string.Format(
_grid.FilteredDataSourcePropertyFormat,
_grid.FilterFieldValue.Replace("'", "''"),
_grid.FilterFieldName
);
}
base.OnPreRender(e);
}
Above, grid is your SPGridView and gridDS is of type ObjectDataSource which I believe is the only type that you will be able to get filtering to work with an SPGridView. Basically, I think what happens is that there is a bug in the Microsoft code and it doesn't really give you a chance to validate the filter value before it gets stuck in the FilterExpression. Using Reflector, I was able to figure out that the SPGridView really just sets the FilterExpression of your datasource. It does this using reflection and the value that you entered for your grid.FilteredDataSourcePropertyName property (I always see it being set to "FilterExpression" in all the examples).
Reference:
http://www.reversealchemy.net/2009/05/24/building-a-spgridview-control-part-2-filtering/

Resources