I'm trying to write a script score function which boosts items who belong to just one category.
new ScriptScoreFunction
{
Script = new ScriptQuery
{
Lang = "painless",
Source = "doc['categories'].values.length == 1",
},
Weight = 10
}
The code below does not seem to work. I'm getting a "bad response code" from the API. What am I doing wrong?
solved by using this as the source of my script:
if (doc['categories.slug'].values.length == 1) { return 1; } return 0;
NOTE: 'slug' is a property of the property 'category'.
Related
I am having an issue with the creation of a Wordcloud with Highcharts 7.1.2 with C# and .NET.
I can create the wordcloud just fine, but I can't set the weight of the words.
The piece of code below is what I currently have, as you can see I am trying to use the Labelrank as a mean to set the weight. I cannot find an example of the wordcloud in c#, but I found some in JS and they always set the weight of each word.
List<Series> seriesList = new List<Series>();
List<WordcloudSeriesData> newWordcloudSeriesDataList = new List<WordcloudSeriesData>();
foreach (var data in datas)
{
newWordcloudSeriesDataList.Add(new WordcloudSeriesData
{
Name = data.Name,
Labelrank = data.Rank
});
}
seriesList.Add(new WordcloudSeries
{
Data = newWordcloudSeriesDataList,
Rotation = new WordcloudSeriesRotation
{
From = 0,
To = 0,
Orientations = 1
}
});
PS: I found a workaround.
When you create the json before sending it to the front, use
chartinfo = chartinfo.Replace("labelrank", "weight");
where chartinfo is the json.
I'm stuck with my problem using " Google.Apis.Testing.v1.Data " and their documentation doesn't help me.
I have to set a "timeout" value (= a duration), but the variable type is "object" instead of "float" for example. I tried to put an int, a float, and a string but that doesn't work.
The object API doc is here. My variable is "TestTimeout" which is definitely a duration.
When I searched for a solution, I saw in java the variable type is string but that doesn't help (here)
Just for your information, I'm using this lib to execute my android application on their test devices. It's a service called TestLab in Firebase. The timeout value needs to be higher because I don't have enough time to execute my test. Here is my code, everything is working well besides this TimeOut.
TestMatrix testMatrix = new TestMatrix();
testMatrix.TestSpecification = new TestSpecification();
testMatrix.TestSpecification.TestTimeout = 600.0f; // I tested 600, 600.0f, "600", "30m", "500s"
testMatrix.EnvironmentMatrix = new EnvironmentMatrix();
testMatrix.EnvironmentMatrix.AndroidDeviceList = new AndroidDeviceList();
testMatrix.EnvironmentMatrix.AndroidDeviceList.AndroidDevices = new List<AndroidDevice>();
foreach (TestMatrixModel.TestData testData in _model.ListTests)
{
if (testData.IsSelected)
{
//Here I'm using my own data class to set GoogleAPI objects, it's simple
//as it asks me strings even for integer numbers, and it's working
foreach (int indice in testData.ChosenAndroidVersionsIndices)
{
AndroidDevice device = new AndroidDevice();
device.AndroidModelId = testData.ModelID;
device.AndroidVersionId = testData.AvailableAndroidVersions[indice];
device.Locale = testData.AvailableLocales[testData.ChosenLocale];
device.Orientation = testData.Orientation;
testMatrix.EnvironmentMatrix.AndroidDeviceList.AndroidDevices.Add(device);
}
}
}
Ok and here is the result of the request :
{
"testMatrixId": "matrix-2dntrwio3kco7",
"testSpecification": {
"testTimeout": "300s",
"testSetup": {},
"androidTestLoop": {
"appApk": {
"gcsPath": "gs://myLinkIntoGoogleCloudStorage.apk"
}
}
},
"environmentMatrix": {
"androidDeviceList": {
"androidDevices": [
{
"androidModelId": "grandpplte",
"androidVersionId": "23",
"locale": "en_001",
"orientation": "landscape"
},
{
"androidModelId": "hero2lte",
"androidVersionId": "23",
"locale": "en_001",
"orientation": "landscape"
},
etc.....
As you can see, it seems to be a string set to "300s"... so why "500s" cannot enter in ?
Thanks a lot.
Ok I got my answer :
testMatrix.TestSpecification.TestTimeout = "600s";
So it was a string and needed to finish with "s". Why that didn't work when I tried ? Just because my code was overrided with another TestSpecification after... my bad.
I am creating a Plugin for CRM Which sets the Title of the page as First Name for Account Entity.
The desired result I have achieved the same by writing a javascript function on formload Event
in CRM.
Following is the code
var titlename = Xrm.Page.data.entity.attributes.get("firstname").getValue();
var titleSpan = document.getElementById('form_title_div');
if(titleSpan) {
for(var i = 0;i < titleSpan.children.length;i++) {
if(titleSpan.children[i].className == 'ms-crm-Form-Title-Data autoellipsis') {
titleSpan.children[i].innerText = titlename;
}
}
}
But my client don't want any javascript code instead he wants it thru Plugin.
I have written a plugin but don't know how to get and set the Title of the page.
Plugin project is a C# Class library.
Code is below for Plugin
Basically I want C# code for commented(Javascipt) Lines
using (var crm = new XrmServiceContext(service))
{
var account = crm.ContactSet.Where(c => c.AccountId == id).First();
var titlename = contact.Crmp_Firstname.ToString();
//var titleSpan = document.getElementById('form_title_div');
//if(titleSpan) {
//for(var i = 0;i < titleSpan.children.length;i++) {
//if(titleSpan.children[i].className == 'ms-crm-Form-Title-Data autoellipsis') {
//titleSpan.children[i].innerText = titlename;
//}
//}
//}
}
Thanks in advance for any help
It is not possible to modify the title of an account form by a plugin.
This because plugins act server side, instead JavaScript (and your account form) is executed client side.
CRM doesn't store the title of the account, but generates it at runtime.
I've just completed a round of refactoring of my application, which has resulted in my removing a project that was no longer required and moving its classes into a different project. A side effect of this is that my User class, which is stored in RavenDB, has a collection property of a type moved to the new assembly. As soon as I attempt to query the session for the User class I get a Json deserialisation error. The issue is touched upon here but the answers don't address my issue. Here's the offending property:
{
"OAuthAccounts": {
"$type": "System.Collections.ObjectModel.Collection`1[
[Friendorsement.Contracts.Membership.IOAuthAccount,
Friendorsement.Contracts]], mscorlib",
"$values": []
},
}
OAuthAccounts is a collection property of User that used to map here:
System.Collections.ObjectModel.Collection`1[[Friendorsement.Contracts.Membership.IOAuthAccount, Friendorsement.Contracts]]
It now maps here:
System.Collections.ObjectModel.Collection`1[[Friendorsement.Domain.Membership.IOAuthAccount, Friendorsement.Domain]]
Friendorsement.Contracts no longer exists. All of its types are now in Friendorsement.Domain
I've tried using store.DatabaseCommands.StartsWith("User", "", 0, 128) but that didn't return anything.
I've tried looking at UpdateByIndex but not got very far with it:
store.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName",
new IndexQuery {Query = "Tag:Users"},
new[]
{
new PatchRequest { // unsure what to set here }
});
I'm using Raven 2.0
Below is a simple sample application that shows you the patching Metadata. While your example is a little different this should be a good starting point
namespace SO19941925
{
internal class Program
{
private static void Main(string[] args)
{
IDocumentStore store = new DocumentStore
{
Url = "http://localhost:8080",
DefaultDatabase = "SO19941925"
}.Initialize();
using (IDocumentSession session = store.OpenSession())
{
for (int i = 0; i < 10; i++)
{
session.Store(new User {Name = "User" + i});
}
session.SaveChanges();
}
using (IDocumentSession session = store.OpenSession())
{
List<User> users = session.Query<User>().Customize(x => x.WaitForNonStaleResultsAsOfNow()).ToList();
Console.WriteLine("{0} SO19941925.Users", users.Count);
}
Operation s = store.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName",
new IndexQuery {Query = "Tag:Users"},
new ScriptedPatchRequest
{
Script = #"this['#metadata']['Raven-Clr-Type'] = 'SO19941925.Models.User, SO19941925';"
}, true
);
s.WaitForCompletion();
using (IDocumentSession session = store.OpenSession())
{
List<Models.User> users =
session.Query<Models.User>().Customize(x => x.WaitForNonStaleResultsAsOfNow()).ToList();
Console.WriteLine("{0} SO19941925.Models.Users", users.Count);
}
Console.ReadLine();
}
}
internal class User
{
public string Name { get; set; }
}
}
namespace SO19941925.Models
{
internal class User
{
public string Name { get; set; }
}
}
UPDATE: Based on the initial answer above, here is the code that actually solves the OP question:
store.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName",
new IndexQuery {Query = "Tag:Users"},
new ScriptedPatchRequest
{
Script = #"this['OAuthAccounts']['$type'] =
'System.Collections.ObjectModel.Collection`1[
[Friendorsement.Domain.Membership.IFlexOAuthAccount,
Friendorsement.Domain]], mscorlib';",
}, true
);
Here are two possible solutions:
Option 1: Depending on what state your project is in, for example if you are still in development, you could easily just delete that collection out of RavenDB from the Raven Studio and recreate all those User documents. All the new User documents should then have the correct class name and assembly and should then deserialize correctly. Obviously, if you are already in production, this probably won't be a good option.
Option 2: Depending on how many User documents you have, you should be able to manually edit each one to specify the correct C# class name and assembly, so that they will be deserialized correctly. Again, if you have too many objects to manually modify, this may not be a good option; however, if there are just a few, it shouldn't be too bad to open each one up go to the metadata tab and paste the correct value for "Raven-Entity-Name" and "Raven-Clr-Type".
I ended up doing this:
Advanced.DatabaseCommands.UpdateByIndex(
"Raven/DocumentsByEntityName",
new IndexQuery {Query = "Tag:Album"},
new []{ new PatchRequest() {
Type = PatchCommandType.Modify,
Name = "#metadata",
Nested= new []{
new PatchRequest{
Name= "Raven-Clr-Type",
Type = PatchCommandType.Set,
Value = "Core.Model.Album, Core" }}}},
false);
I am in need of getting the manufacturer's name, given a product code. The following code stub returns the manufacturer's ID (values like 109, 120, etc.). Is there a way to get the manufacturer's name insted of the ID? I can see that there are some good examples in PHP for this question but I am looking for the answer in C#. Any help would be greatly appreciated! Thanks in anticipation!
The current code is:
public bool GetProductInfo(salesOrderItemEntity objProduct, ref StructProductInfo structProductInfo)
{
bool bSuccess = false;
catalogProductRequestAttributes attrib = new catalogProductRequestAttributes();
attrib.additional_attributes = new string[] { "manufacturer" };
catalogProductReturnEntity objProductInfo = null;
objProductInfo = mservice.catalogProductInfo(mlogin, objProduct.product_id, "default", attrib, null);
if (null != objProductInfo)
{
associativeEntity[] assoc = objProductInfo.additional_attributes;
structProductInfo.ManufacturerCode = assoc[0].value;
bSuccess = true;
}
return bSuccess;
}
Manufacturer is an integer "eav_attribute" by default, and that is why you will get integer values.
You will need to get the join to the manufacturers data set up in magneto.
Not exactly sure how to do that data from the API end.
Maybe try attribute options, instead of additional attributes, and then get the label for that option.
Figured out how to do this. "102" is the attribute code for "manufacturer". Using this with catalogProductAttributeOptions(), I have built a small hashtable-based lookup for getting a manufacturer's name, given the manufacturer's code.
public void CreateManufacturerLookup()
{
mhtManufacturers.Clear(); // mhtManufacturers is a hashtable declared with class scope
catalogAttributeOptionEntity[] caoe = mservice.catalogProductAttributeOptions(mlogin, "102", "default"); // mlogin is the session ID and is available at class scope
if (caoe.Length > 0)
{
for (int i = 0; i < caoe.Length; i++)
{
mhtManufacturers.Add(caoe[i].value, caoe[i].label);
}
}
}
So, manufacturer's name can be obtained by looking up as follows:
sManufacturerName = (string) mhtManufacturers[sManufacturerCode];