Is there a possibility to retrieve an advanced find query/fetchxml on a result page? Before I trigger Results button I am able to press Fetchxml button but on a results page not. Is there a possibiltiy to retrieve this query/xml via javascript or C# and it has to be on a results page.
I am not 100% sure if we are talking about the same thing, but it is possible to state a query using Fetchxml.
Have a look at this page.
Here they use FetchExpression(string) to query with the regular organization service. You just need the organization service and the fetchxml to query it. Little example (from the link above!):
// Retrieve all accounts owned by the user with read access rights to the accounts
and
// where the last name of the user is not Cannon.
string fetch2 = #"
<fetch mapping='logical'>
<entity name='account'>
<attribute name='accountid'/>
<attribute name='name'/>
<link-entity name='systemuser' to='owninguser'>
<filter type='and'>
<condition attribute='lastname' operator='ne' value='Cannon' />
</filter>
</link-entity>
</entity>
</fetch> ";
EntityCollection result = _serviceProxy.RetrieveMultiple(new
FetchExpression(fetch2));
foreach (var c in result.Entities)
{
System.Console.WriteLine(c.Attributes["name"]);
}
As you see this is most likely a console job. How you use the Entities itself then is up to you.
As far as I know, there are no hooks to customize the Advanced Find page, so there's no way to add JavaScript to do what you want.
However, you could write a plugin that fires on the RetrieveMultiple message.
In the plugin you can get the QueryExpression from the RetrieveMultipleRequest
var q = (QueryExpression)context.InputParameters["Query"];
Then convert it to FetchXML.
var conversionRequest = new QueryExpressionToFetchXmlRequest
{
Query = q
};
var conversionResponse = (QueryExpressionToFetchXmlResponse)_serviceProxy.Execute(conversionRequest);
var fetchXml = conversionResponse.FetchXml;
Please note I have not tested the above code. And since I have not done this exact technique it's possible that you can cast the Query directly to FetchXML and skip the conversion call.
So, you might want to try this:
var q = (FetchExpression)context.InputParameters["Query"];
RetrieveMultiple plugins have their caveats. But, how bad is it?
On a related note, if the user saves the Advanced Find as a personal view, its FetchXML can be retrieved from the UserQuery entity.
Related
If using Facebook's graph explorer, I could do https://graph.facebook.com/v14.0/ads_archive followed by the access token and search parameters, and it returns the ads posted by pages in a given country?
Can I do the same type of query using RestFB?
Thanks
Maybe you have to use the JsonObject as return value, but in general: yes:
FacebookClient facebookClient = new DefaultFacebookClient("access token", Version.VERSION_14_0);
JsonObject return = facebookClient.fetchObject("ads_archive", JsonObject.class, Parameter.with("search query parameter", "search query value"));
The access token is added automatically to the request, and you have only to provide the search parameters. If you have more than one parameter, just add them. A parameter list can be handeled by the fetchObject method.
If the result is a connection (the Facebook version of a page-able list) use fetchConnection instead of fetchObject. RestFB takes care of the paging.
This question already has answers here:
Filtering Entities with type Entity Reference?
(3 answers)
Closed 5 years ago.
I'm retrieving the results after connecting to the dynamics CRM as below:
CrmServiceClient crmConn = new CrmServiceClient(ConfigurationManager.ConnectionStrings["default"].ConnectionString);
IOrganizationService crmService = crmConn.OrganizationServiceProxy;
QueryExpression query = new QueryExpression("opportunity");
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("name", ConditionOperator.Like, "14%");
EntityCollection results = crmService.RetrieveMultiple(query);
Now as the name is of type string, I was able to add condition & perform operations & get the results.
My requirement is I've to add another filter which is a lookup property "parentaccountid".
I'm trying to add the condition as below but it throws cast exception error as it is expecting only GUID.
query.Criteria.AddCondition("parentaccountid", ConditionOperator.Like, "%In%");
Note: the type of parentaccountid is Microsoft.Xrm.Sdk.EntityReference when I retrieved from early results
The reason is we can apply filter for parentaccountid only with GUID.
Is there any way to add the condition based on "Name" instead of "Id"?
Yes, just add "name" to the end of "parentaccountid":
query.Criteria.AddCondition("parentaccountidname", ConditionOperator.Like, "%In%");
You'll notice that if you create an Advanced Find like this:
And then download the FetchXML, CRM just appends "name" to the end of lookup attribute name:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="opportunity">
<attribute name="name" />
<order attribute="name" descending="false" />
<filter type="and">
<condition attribute="parentaccountidname" operator="like" value="%In%" />
</filter>
</entity>
</fetch>
An alternative solution would be to use a LinkEntity, and query the name of the linked account.
There are a few articles online how to apply your custom filter to lookup field. I thought there couldn't be anything simpler and yet..
function addFilter(accountId) {
//create a filter xml
var filter = "<filter type='and'>" +
"<condition attribute='parentaccountid' operator='eq' value='"+accountId+"'/>" +
"</filter>";
//add filter
Xrm.Page.getControl("my_lookup_field").addCustomFilter(filter);
}
I want to see in the lookup quick find view only accounts that parent account is set to specific account. Yet once I apply this filter no account will display in the view. I am really lost.
You must also run a function on load of your form which calls your addFilter(accountId) function. Something like:
function preFilterLookup() {
var accountId = Xrm.Page.getAttribute("parentaccountid").getValue();
Xrm.Page.getControl("my_lookup_field").addPreSearch(function () {
addFilter(accountId);
});
}
This will only work in CRM 2013 and above.
First you have to understand, how this addPreSearch & addCustomFilter works. Whatever filter xml we pass will get added to the predefined lookup view definition on runtime. Check the contact record for right parent account Id, hard code it in your filter & see.
This can be achieved in many ways based on your CRM version. In 2015 MS introduced no code solution as 'Related records Filtering'. try this if you can see this option.
I have a simple WebAPI2 service that uses OData (System.Web.Http.OData, 5.1.0.0). Users can hit /odata/$metadata to get the available entities and properties. I'm looking for a way to extend this metadata with additional information, such as adding a "display name" value to a property.
I found information about "annotations" that sounds like it is what I want, but I cannot find anything explanining how to use this in my scenario or if it is even possible. I was trying to do something like the following:
model.SetAnnotationValue(((IEdmEntityType)m.FindType("My.Thing")).FindProperty("SomeProperty"),
namespaceName:"MyNamespace",
localName: "SomeLocalName",
value: "THINGS");
The type/property names are correct and the call succeeds, but the OData EDMX document does not contain this annotation. Is there some way to expose these annotations or otherwise do what I want?
Update:
Still at it. I've been looking at ODataMediaTypeFormatters as a possible way to handle this. There is an ASP.NET sample project that shows how to add instance annotations to entities. Close, but not exactly what I want, so now I'm trying to find a way to extend whatever generates the metadata document in a similar way.
I figured out a way to do this. The code below adds a custom namespace prefix "myns" and then adds an annotation on a model property:
const string namespaceName = "http://my.org/schema";
var type = "My.Domain.Person";
const string localName = "MyCustomAttribute";
// this registers a "myns" namespace on the model
model.SetNamespacePrefixMappings(new [] { new KeyValuePair<string, string>("myns", namespaceName), });
// set a simple string as the value of the "MyCustomAttribute" annotation on the "RevisionDate" property
var stringType = EdmCoreModel.Instance.GetString(true);
var value = new EdmStringConstant(stringType, "BUTTONS!!!");
m.SetAnnotationValue(((IEdmEntityType) m.FindType(type)).FindProperty("RevisionDate"),
namespaceName, localName, value);
Requesting the OData metadata document should give you something like this:
<edmx:Edmx Version="1.0">
<edmx:DataServices m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0">
<Schema Namespace="My.Domain">
<EntityType Name="Person">
<Key><PropertyRef Name="PersonId"/></Key>
<Property Name="RevisionDate" Type="Edm.Int32" Nullable="false" myns:MyCustomAttribute="BUTTONS!!!"/>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
You can set a custom property to any IEdmEntityType, thus also for . Simply modify kenchilada's code as follows:
m.SetAnnotationValue(m.FindType(type), namespaceName, localName, value);
This code works to get content from the broker for all components whos name begins with "MC":
Criteria c1 = new ItemTitleCriteria("MC%", Criteria.Like);
//Create query
Query myQuery = new Query(c1);
String[] itemURIs = myQuery.ExecuteQuery();
ComponentPresentationAssembler cpAssembler = new ComponentPresentationAssembler();
foreach (string componentUri in itemURIs)
{
String content = cpAssembler.GetContent(componentUri, componentTemplateUri);
}
However, I am struggling to find in the api where I can actually access the names (or titles) of each component returned.
I'm not sure if the broker API has such capabilities to retrieve those attributes. You may probably need to use another library to retrieve information from the CMS.
But to answer your question, one way to get the title if to publish it to the brokerDB as part of the content (cpAssembler.GetContent()). Just make sure that you render Component.Title in the component template. Once it's in the DB, you can parse it.
Sample content:
<model id="modelId" title="componentTitle" />
Note: Tridion has its own StackExchange site now, you may get more interaction there. https://tridion.stackexchange.com/