How can I search Dynamics CRM using OrganizationService for a specific record? - vb.net

If I know the accountId of a record I can do something like this:
Dim cols As New ColumnSet(New String() {"name",
"address1_postalcode",
"lastusedincampaign"})
Dim retrievedAccount As Account = _orgService.Retrieve("account", _accountId, cols).ToEntity(Of Account)()
But what if I don't know the accountId and instead want to search for a record based on some other factor? Say, returning all records with "John" as the first name?

You have to use the RetrieveMultiple method with a QueryExpression.
See this link for some examples
You could also use Linq to CRM, or Fetch XML.

You can use QueryExpression as explained here:
http://msdn.microsoft.com/en-us/library/gg328300.aspx.
You can write your own ConditionExpression or FetchXml for the QueryExpression.
For more complicated query I like to use FetchXml. You can do Advanced Find then download the generated FetchXml, or use any number of online tools like Fetch Xml Builder to generate it first.
Hope that helps.

Related

Retrieve a document class-description symbolicName without fetching

I'm triying to retrieve a ClassDescription symbolicName of an IDocument object. It seems that i have to fetch its ClassDescription even if I just want the symbolicName.
Is there a way to do it ? I just want to avoid doing a fetch for every browsed document...
(Also IDocument.GetClassName doesn't help, it returns "Document")
I finally found a way, by making an SQL SELECT request retrieving the classDescription ID (which is not the symbolicName ID, but rather an "internal" one) :
Select This, d.Id, d.ClassDescription
From Document d
where d.Id = ID
It seems to be lighter than a line like document.fetch(classDescription) (pseudo call) cause it should just retrieves the ID.
I thought it worth mentioning a problem regarding the accepted answer.
There are times that doing a query would be "lighter" however I believe you are missing something involving fetching a document.
FileNet's fetchInstance command can take in a PropertyFilter.
In your case you could do something along the lines of:
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, "ClassDescription", null));
doc = Factory.Document.FetchInstance(os, new Id("doc.ID()"), pf);
You would probably want to look at your original fetch of this document and make sure to specify the full list of property filters at that point.
See Working With Documents

read all document by using particular category name using alfresco search.luceneSearch or search.lib.js

Category Name
|
Geograpy (8)
Study Db (18)
i am implement my own advance search in alfresco. i need to read all files which related with particular category.
example:
if there is 20 file under geograpy, lucene query should read particular document under search key word "banana".
Further explanation -
I am using search.lib.js to search. I would like to analyze the result to find out to which category the documents belong to. For example I would like to know how many documents belong to the category under Languages and the subcategories. I experimented with the Classification API but I don't get the result I want. Any Idea how to go through the result to get the category name of each document?
is there any simple method like node.properties["cm:creator"]?
thanks
janaka
I think you should specify more your question:
Are you using cm:content or a customized content?
Are you going to search the keyword inside the content of the file? or are you going to search the keyword in a specific metadata(s)?
Do you want to create a webscript (java or javascript)?
One thing to take in consideration:
if you use +PATH:"cm:generalclassifiable/...." for the categorization in your lucene queries, the performance will be slow (following my experince)
You can use for example the next query to find all nodes at any depth below /cm:Languages:
var results = search.luceneSearch("+PATH:\"cm:generalclassifiable/cm:Languages//*\");
Take a look to this url: https://wiki.alfresco.com/wiki/Search#Path_Queries
Once you have all the elements, you can loop all, and get to which category below. Of course you need to create some counter per each category/subcategory:
for(i = 0; i < results.length; i++){
var node = results[i];
var categoryNodeRef = node.properties["cm:categories"];
var categoryDesc = categoryNodeRef.properties["cm:description"];
var categoryName = categoryNodeRef.properties["cm:name"];
}
This is not exactly the solution, but can be a useful idea to start.
Sorry if it's not what you're asking for, I have just arrived from my holidays.

Ektron solr search with smartform fields facing aproblem

I am working with ektron 9.
I have created a smart from,and implemented the search for smart form fields using search api.
For that am using Ektron.Cms.Framework.Search.SearchManager class.It works fine when for single Xpath values.
When my smart form has multiple fields with same Xpath,the search api is returning the results of first occurrence only.
In the below example ,when i search for Book->Title using Xpath "/root/Books/Book/Title" search always return "Hai" in result.
<root>
<Books>
<Book>
<Id>1
</Id>
<Title>Hai
</Title>
<Book>
<Book>
<Id>2
</Id>
<Title>Hello
</Title>
<Book>
</Books>
</root>
How can i get "Hello" also in the result? is any separate api to handle this?
Or is it possible to handle this scenario in a separate way,like by specifying like this "/root/Books/Book[id=1]/Title" ?
For more details on search please look:
http://documentation.ektron.com/cms400/v85/webhelp/Navigating/Search85/APISearch.htm#Major
You haven't provided the code you are using so it is difficult to see where you are going wrong.
However, here is some code that will allow you to search against a SmartForm field in Ektron using Solr (or Microsoft Search Server).
This searches against a specific SmartForm in a field called "Path" - which is accessed using the XPath "/root/Path".
Ektron.Cms.Framework.Search.SearchManager sManager = new Ektron.Cms.Framework.Search.SearchManager();
AdvancedSearchCriteria searchCriteria = new AdvancedSearchCriteria();
searchCriteria.ExpressionTree = SearchContentProperty.XmlConfigId.EqualTo(YourSmartFormID);
searchCriteria.ExpressionTree &= SearchSmartFormProperty.GetStringProperty("/root/Path").EqualTo(YourPathValue);
searchCriteria.PagingInfo = new PagingInfo(10, 1);
searchCriteria.ReturnProperties = new HashSet<PropertyExpression>
{
SearchContentProperty.Id,
SearchContentProperty.Title,
SearchContentProperty.QuickLink
};
SearchResponseData response = sManager.Search(criteria);
The above example asks Search (Solr or Search Server) to return three properties: Id, Title and QuickLink.
You are likely to need to add "using" statements for Ektron.Cms.Search and Ektron.Cms.Framework.Search if you have not already.
Your best reference guide for the Ektron API is this site.
Ektron 9's solr integration has been fairly buggy for me thusfar (granted, it isn't even really out yet!), so this may actually just be a bug.
That said, does the same thing happen when you select /root/Books/Book, or does that also return only one result?
If the API is only ever returning one result, you could try making the search several times, until it comes up empty. The general pseudocode algorithm would be:
var i = 0;
List<item> allItems = new List<item>();
item myItem = select("(/root/Books/Book/Title)[0]");
while(myItem != null){
allItems.add(myItem);
i++;
myItem = select("(/root/Books/Book/Title)["+i+"]");
}
keeping in mind that this is pretty crazy inefficent.
Solr supports multivalued attributes, so when indexing smartform fields they get indexed as true multivalued fields instead of a delimiter separated values as was the case with Search Server 2010/FAST 2010.
In case of multivalued fields, from the SearchResponseData you would have to use the SearchResultData returned in the following manner.
For the case of Multivalued String properties
GetValue(StringMultiValuePropertyExpression) or use the indexer [StringMultiValuePropertyExpression]
For the case of Multivalued Floating point properties
GetValue(DecimalMultiValuePropertyExpression) or use the indexer [DecimalMultiValuePropertyExpression]
Reference
http://reference.ektron.com/developer/framework/Search/SearchResultData/
In case one doesn't use the MultiValuePropertyExpression, the API will return the first value of the set of values which is what you are seeing.
Hope this helps.

Endeca UrlENEQuery java API search

I'm currently trying to create an Endeca query using the Java API for a URLENEQuery. The current query is:
collection()/record[CONTACT_ID = "xxxxx" and SALES_OFFICE = "yyyy"]
I need it to be:
collection()/record[(CONTACT_ID = "xxxxx" or CONTACT_ID = "zzzzz") and
SALES_OFFICE = "yyyy"]
Currently this is being done with an ERecSearchList with CONTACT_ID and the string I'm trying to match in an ERecSearch object, but I'm having difficulty figuring out how to get the UrlENEQuery to generate the or in the correct fashion as I have above. Does anyone know how I can do this?
One of us is confused on multiple levels:
Let me try to explain why I am confused:
If Contact_ID and Sales_Office are different dimensions, where Contact_ID is a multi-or dimension, then you don't need to use EQL (the xpath like language) to do anything. Just select the appropriate dimension values and your navigation state will reflect the query you are trying to build with XPATH. IE CONTACT_IDs "ORed together" with SALES_OFFICE "ANDed".
If you do have to use EQL, then the only way to modify it (provided that you have to modify it from the returned results) is via string manipulation.
ERecSearchList gives you ability to use "Search Within" functionality which functions completely different from the EQL filtering, though you can achieve similar results by using tricks like searching only specified field (which would be separate from the generic search interface") I am still not sure what's the connection between ERecSearchList and the EQL expression above?
Having expressed my confusion, I think what you need to do is to use String manipulation to dynamically build the EQL expression and add it to the Query.
A code example of what you are doing would be extremely helpful as well.

MOSS 2007: What is the source of "Directories"?

I'm trying to generate a new SharePoint list item directly using SQL server. What's stopping me is damn tp_DirName column. I have no ideas how to create this value.
Just for instance, I have selected all tasks from AllUserData, and there are possible values for the column: 'MySite/Lists/Task', 'Lists/Task' and even 'MySite/Lists/List2'.
MySite is the FullUrl value from Webs table. I can obtain it. But what about 'Lists/Task' and '/Lists/List2'? Where they are stored?
If try to avoid SQL context, I can formulate it the following way: what is the object, that has such attribute as '/Lists/List2'? Where can I set it up in GUI?
Just a FYI. It is VERY not supported to try and write directly to SharePoint's SQL Tables. You should really try and write something that utilizes the SharePoint Object Model. Writing to the SharePoint database directly mean Microsoft will not support the environment.
I've discovered, that [AllDocs] table, in contrast to its title, contains information about "directories", that can be used to generate tp_DirName. At least, I've found "List2" and "Task" entries in [AllDocs].[tp_Leaf] column.
So the solution looks like this -- concatenate the following 2 components to get tp_DirName:
[Webs].[FullUrl] for the web, containing list, containing item.
[AllDocs].[tp_Leaf] for the list, containing item.
Concatenate the following 2 components to get tp_Leaf for an item:
(Item count in the list) + 1
'_.000'
Regards,
Well, my previous answer was not very useful, though it had a key to the magic. Now I have a really useful one.
Whatever they said, M$ is very liberal to the MOSS DB hackers. At least they provide the following documents:
http://msdn.microsoft.com/en-us/library/dd304112(PROT.13).aspx
http://msdn.microsoft.com/en-us/library/dd358577(v=PROT.13).aspx
Read? Then, you know that all folders are listed in the [AllDocs] table with '1' in the 'Type' column.
Now, let's look at 'tp_RootFolder' column in AllLists. It looks like a folder id, doesn't it? So, just SELECT the single row from the [AllDocs], where Id = tp_RootFolder and Type = 1. Then, concatenate DirName + LeafName, and you will know, what the 'tp_DirName' value for a newly generated item in the list should be. That looks like a solid rock solution.
Now about tp_LeafName for the new items. Before, I wrote that the answer is (Item count in the list) + 1 + '_.000', that corresponds to the following query:
DECLARE #itemscount int;
SELECT #itemscount = COUNT(*) FROM [dbo].[AllUserData] WHERE [tp_ListId] = '...my list id...';
INSERT INTO [AllUserData] (tp_LeafName, ...) VALUES(CAST(#itemscount + 1 AS NVARCHAR(255)) + '_.000', ...)
Thus, I have to say I'm not sure that it works always. For items - yes, but for docs... I'll inquire into the question. Leave a comment if you want to read a report.
Hehe, there is a stored procedure named proc_AddListItem. I was almost right. MS people do the same, but instead of (count + 1) they use just... tp_ID :)
Anyway, now I know THE SINGLE RIGHT answer: I have to call proc_AddListItem.
UPDATE: Don't forget to present the data from the [AllUserData] table as a new item in [AllDocs] (just insert id and leafname, see how SP does it itself).