SPQuery sorting issue - visual-studio-2010

I have this SPListItem.Folder in sharepoint that contains a property named "Asset ID".
I have this data in my list
Asset ID | Name | Asset Type
1 | GamesFolder | Games
2 | AppsFolder | softwares
3 | MusicFolder | music
In my code I did this
SPList objList = web.Lists["MyList"];
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='Asset ID' Ascending='FALSE'/></OrderBy>";
query.ViewAttributes = "Scope=\"Recursive\"";
query.RowLimit = 1;
SPListItemCollection items = objList.GetItems(query);
return objList.Items[0].Folder.Properties["Asset ID"].ToString();
I use .Folder because every entry in the list is a DocumentSet.
The returned value is always "1". I don't know what's wrong why my sorting
doesn't work at all.
Please help me resolve this issue. Thanks.

Hi Carls I think there is issue for field name. U include space in field name
If you want to avoid having to seek out what the internal name of a particular field is, when you first name your column, do not include any spaces or special characters. Once the field (column) has been created, go back and rename the field to include the spaces or special characters as desired. SharePoint will still retain the original field name without spaces and you can use that directly in your query without issue.

or use its internalName:
query.Query = "<OrderBy><FieldRef Name='Asset_x0020_ID' Ascending='FALSE'/></OrderBy>";

A little late but if you are having issues, you may be able to use all or a part of the following gist:
https://gist.github.com/trgraglia/4672176
And as the accepted answer states, the field name is the issue. You need to use the static name of the field. The static name will always stay the same. Even if the column is renamed. So you should get the column from the column collection by display name and then get the static name from the properties.

Related

Acumatica - Filtering PO Inventory Selector By Current Vendor

I have a customer that wants the Inventory Selector in POLine to only contain inventory items that belong to the selected vendor in POOrder. Is there a way to add a join to [POLineInventoryItem(Filterable=true)]? Or some other way I should go about this?
If I replace with new pxselector the inventory item does not pass to po line. Also, I will lose the CrossAttribute search. This is the Acumatica code:
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[POLineInventoryItem(Filterable = true)]
[PXForeignReference(typeof(FK.InventoryItem))]
This is the selector I need:
[PXSelector(typeof(Search2<InventoryItem.inventoryID,
InnerJoin<POVendorInventory, On<InventoryItem.inventoryID,
Equal<POVendorInventory.inventoryID>,
And<POVendorInventory.vendorID, Equal<Current<POOrder.vendorID>>>>>>))]
[PXCustomizeSelectorColumns(
typeof(PX.Objects.IN.InventoryItem.inventoryCD),
typeof(PX.Objects.IN.InventoryItem.descr),
typeof(PX.Objects.IN.InventoryItem.itemClassID),
typeof(PX.Objects.IN.InventoryItem.itemType),
typeof(PX.Objects.IN.InventoryItem.baseUnit),
typeof(PX.Objects.IN.InventoryItem.salesUnit),
typeof(PX.Objects.IN.InventoryItem.purchaseUnit),
typeof(PX.Objects.IN.InventoryItem.basePrice),
typeof(PX.Objects.IN.InventoryItem.itemStatus))]
When I replace the selector with the one #Brian suggested, even with a leftjoin, I get back a SQL syntax error happening in this snippet in profiler:
FROM [InventoryItem] [InventoryItem]
WHERE ( [InventoryItem].[CompanyID] = 2) AND
[InventoryItem].[DeletedDatabaseRecord] = 0 AND
( [InventoryItem].[InventoryID] = )
ORDER BY [InventoryItem].[UsrCaseQty]),
(SELECT TOP (1) [InventoryItem].[BaseItemVolume]
Updated: The previous answer did not apply as the existing selector does not include the needed DAC, so we need to use redefine the selector as well. If we use the MergeMethod Append, the original attribute will still return all results, so this selector will be ignored. Since we are using Replace, we need to include all other attributes that we want included.
[PXMergeAttributes(Method = MergeMethod.Replace)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXSelector(typeof(Search2<InventoryItem.inventoryID,
InnerJoin<POVendorInventory, On<InventoryItem.inventoryID,
Equal<POVendorInventory.inventoryID>,
And<POVendorInventory.vendorID, Equal<Current<POOrder.vendorID>>>>>>),
typeof(InventoryItem.inventoryID),
typeof(InventoryItem.inventoryCD),
typeof(InventoryItem.descr),
typeof(InventoryItem.itemClassID),
typeof(InventoryItem.itemType),
typeof(InventoryItem.baseUnit),
typeof(InventoryItem.salesUnit),
typeof(InventoryItem.purchaseUnit),
typeof(InventoryItem.basePrice),
typeof(InventoryItem.itemStatus),
SubstituteKey = typeof(InventoryItem.inventoryCD)
)]
protected virtual void POLine_InventoryID_CacheAttached(PXCache sender) { }
You could do this in a DAC extension, but this example assumes you only want this in a specific screen/graph. The use of CacheAttached will override the field, but only from the graph where defined.
Note that this example should work for what you asked specifically, but my tests shows that it also will prevent showing the inventory ID of a PO Line if there is no PO Vendor Inventory record tying a pre-existing line to the current vendor.

Custom field called instead of the default field 'name' in m2o field in odoo

There is a field name partner_id in model mail.channel.partner. I want that the partner_id return "Joestar" instead of it's full name 'Joseph joestar'. This should be apply only on this model .
How can I modify the partner_id(m2o) so that it will return only the last string. The goal of this is to hide the full name of the users/partners that's why I need the last string only.
The goal is when we interact to our customer through our site, we don't want to reveal our full name instead, we want to display only the last name.
In the image below, The encircled data is the name I want to modify to last name instead of full name.
enter image description here
Hello Marychan,
Please Override name_get method that'll already define in res.partner model like this:
#api.multi
def name_get(self):
result = []
for rec in self:
result.append((rec.id, "%s" % (rec.name.strip().split()[-1])))
return result
That will give you only last word of name.
If you want to check the url for you model:-
from openerp import http
print http.request.env['ir.config_parameter'].get_param('web.base.url') # BASE URL
print http.request.httprequest
print http.request.httprequest.full_path
Check before stripping and spliting

get data from other filed in odoo

I need to get value field2 from list values in field1. Field1 is relation many2many with field in another model.
I tried to use domain for it but everytime I received error.
class filial_page_products(models.Model):
gallery_rstamp_products_ids = fields.Many2many('product.template',
'gallery_rstamp_products_rel',
'gallery_rstamp_products_ids', 'filial_page_new_rstamp_products_ids',
'Gallery products')
default_gallery_product_id = fields.Many2one('product.template','Default maket', domain="[(default_gallery_product_id, 'in', 'filial_page_gallery_rstamp_products_ids')]")
class product(models.Model):
_inherit = 'product.template'
filial_page_gallery_rstamp_products_ids = fields.Many2many('product.template',
'gallery_rstamp_products_rel',
'filial_page_recovery_rstamp_products_ids', 'gallery_rstamp_products_ids',
'Gallery list')
filial_page_default_maket_product_ids = fields.One2many('pr_filials.filial_page_products',
'default_gallery_product_id',
'Linked page products')
How can I use domain to select only those values that are specified in the gallery_rstamp_products_ids field?
of course, I can set default_gallery_product_id from all products but I don't like it.
Your domain doesn't look quite right. The left operand should be quoted and the right side should not be quoted (unless it's actually supposed to be evaluated as a string).
domain="[('default_gallery_product_id', 'in', filial_page_gallery_rstamp_products_ids)]"
Note, there's a special format required for filtering against x2many fields (one2many or many2many). You may need to use this (below), however, there have been reports of issues using this in newer versions.
domain="[('default_gallery_product_id', 'in', filial_page_gallery_rstamp_products_ids[0][2])]"
Here's some documentation on domains.

Getting value of database field in Crystal Reports

Currently I'm working on legacy application, that uses crystal report engine. I have to get value of database fields programmatically. As I've assumed, I need proper event for getting next code to work:
Report.Database.Tables(1).Fields(1).Value
But the value is always empty in DownloadStarted/Finished event handlers. What I'm doing wrong and is it at least possible?
I think that if you want to get value of your table fields in program the best way is that you get the field name from report and then connect to your table directly and use report field names as the table columns name
i do it in c# i hope it can help you in vb6 too:
string name = report2.Database.Tables[1].Fields[1].Name;
string[] names = name.Split('.');
and then add your database to your program and use names like this:
DataTable dt = new DataTable();
string[] value = dt.Columns[names[1]];
if you just need your tables values, you can use my last answer, but if you need value of database fields in crystal report, i mean something like formula field ,this code can help you:
CRAXDRT.FormulaFieldDefinitions definitions = report2.FormulaFields;
string formulaText = "IF " + report2.Database.Tables[1].Fields[3].Name
+ " > 10 THEN" + report2.Database.Tables[1].Fields[2].Name;
definitions.Add("Test", formulaText);
report2.Sections[1].AddFieldObject(definitions[1], 0, 0);

Finding Last Name Using LINQ

I am trying to get last name using linq in visual studio. In my database, i have the Field name like "FullName".
In this Field I have value like "Subbu Cargos"
I Wanna Display the "Cargos" in my textbox.
How can i make a simple linq query?
Would it be over simple to say:
return FullName.Split(' ').Last()
?
I would suggest breaking it up into different fields - Firstname, Middlename, lastname, Title - and rebuilding the name on the fly when you come to display it.
If you're still determined to use one field, then consider a query like:
string s = "Subba Cargos";
var lastnames = from name in s.Split(new Char[] { ' ' }).Last<string>()
select name;
I would suggest not trying to parse out the last name. Like you say, first and last names could be switched around, someone might have a second name, or a last name that consists of multiple words (“van Dijk”), or may not have entered a last name at all.
Check out this article: Falsehoods Programmers Believe About Names
If you still want to do this however, try something like this:
customers.Select(c => c.FullName.Split(' ').Last());
You might not be able to this on the server side. In that case:
customers
.Select(c => c.FullName)
.ToList()
.Select(n => n.Split(' ').Last());
Untested, but this should give a rough idea.
You could also do it like this:
customers
.Select (b => b.FullName.Substring ((b.FullName.IndexOf(' ') + 1)));

Resources