I've been trying to use Schema.NET to generate HowTo schema on certain articles. I have not been able to use this because I can only add a single step to the HowTo element. Google validation says I need at least 2 steps. Google samples show a step array, but again, I can only add a single step using Schema.NET.HowTo class.
var schema = new HowTo()
{
Name = "How to tie make pie",
Description = "If you want to make pie...",
Step = //This property's type is Values<ICreativeWork, IHowToSection, IHowToStep, string>
};
For reference, here are Google's examples: https://developers.google.com/search/docs/data-types/how-to#standard
Any idea on how to make this work?
I just look closer at the Values object and noticed you can use an array of IHowToStep object.
Related
Consider the following data
I am trying to update the property name from givenName to PetName. Below are the things I tried.
Option 1:
List<PatchOperation> patchOperations = new List<PatchOperation>();
dynamic data = new
{
PetName= "Dummy"
};
//Remove the 0th element from the pet array
patchOperations.Add(PatchOperation.Remove("/children/0/pets/0"));
//insert the new entity
patchOperations.Add(PatchOperation.Add<dynamic>("/children/0/pets/0", data));
await Container.PatchItemAsync<dynamic>("AndersenFamily", new
PartitionKey("AndersenFamily"), patchOperations);
This works on the first element (as I have specified the index as 0).
But I couldn't find a way to update all the elements in the array. Something like /children/*/pets (I get an error "Invalid navigation for array(*)").
Option 2:
Read all the data from the database, remove the existing pets and upload the new object with the property PetName. But I guess it will take lot of time to loop through all the objects and make these changes.
Can someone suggest a better solution or a way to fix the partial updates so that it updates all the elements in the array?
The actual dataset that I am working on is huge and has more nested arrays.
Yes you are right, Current version of Patch does not support patching nested array. You need to know the index in order to replace/add values as you mentioned in the first question.
One way to think about this would be to write your own logic to replace the keys , there are libraries available in dotnet and then using the bulk insert using the SDK to insert those documents.
I wanted to know how it's possible to do some simple CouchbaseLite queries.
I have a document named "test", with key-values "id": 5 and "name":"My first test".
I wanted to search following:
I want to get the id (5) where name = "My first test".
I also wanted to know if this name = "My first test" entry is already available? I only wanted to add it if it's not there.
Database db = new Database("test_db");
using (var testDoc = new MutableDocument("test"))
{
testDoc.SetInt("id", 5)
.SetString("name", "My first test");
db.Save(testDoc);
}
Thanks!
Assuming I understood your question right that you want to fetch documents with a specific property value only if it exists, you can do something like this
var query = QueryBuilder.Select(SelectResult.expression(Meta.id),
SelectResult.expression(Expression.property("id")))
.From(DataSource.Database(db))
.Where(Expression.Property("name").NotNullOrMissing()
.And(Expression.Property("name").EqualTo(Expression.string("My first test"))))
Alternatively, if you know the Id of the document, it would be faster to do a GetDocument with the Id. Once you have the document, do a GetString on the name property. If it returns null, you can assume it does not exist.
Refer to the documentation on Couchbase Lite query fundamentals here.There are several examples. You may also want to check out API specs on NotNullOrMissing
So I have a slightly interesting problem right here. What I'm trying to achieve is to add between 1000 to 2000 string variables to the list and later compare them with another strings. So far I can achieve this by using below code:
var list = new List<string>();
var item_1 = "USA";
var item_2 = "Canada";
var item_3 = "Cuba";
...................
var item_N = "Country_N";
list.Add(item_1);
list.Add(item_2);
list.Add(item_3);
.................
list.Add(item_N);
And comparing them with another strings looks like below (using FluentAssertions class):
list[0].Should().Match(stringToCompare_1);
list[1].Should().Match(stringToCompare_2);
list[2].Should().Match(stringToCompare_3);
The biggest problem that I see here is it's sort of hard to memorize what string was added to a particular index of the list (unstoppable scrolling between the code is boring). My question: is there any more elegant way to handle this situation? Something that might look like below (List class method ValueOf is fictional):
var list = new List<string>();
var item_1_USA = "USA";
var item_2_Canada = "Canada";
var item_3_Cuba = "Cuba";
list.ValueOf(item_1_USA).Should().Match(stringToCompare_1);
list.ValueOf(item_1_Canada).Should().Match(stringToCompare_2);
list.ValueOf(item_1_Cuba).Should().Match(stringToCompare_3);
As many suggested (including #Postlagerkarte) to edit the question to clarify what I'm trying to achieve. I'm testing the web app, and while going through every step of this application (imagine booking engine), I need to capture and store different info (like user's First Name, Last Name, Email Address, Phone Number, etc). The amount of the captured info can sometimes exceed 2000 items. Currently I'm using data structure List. Later, at the final step of my application, I need to compare my stored values with what ever present on this final page. For instance: user's first name, that was captured on Step 2 of the booking engine must match with value on final step. List Contains method won't be suitable here as it can validate incorrect information. Accessing the values using list[0]....list[N] is very inconvenient, as I can forget what exactly was stored at that index. I'm solving it now by scrolling through the code to return back. Any wise navigation is appreciated.
You can use a Dictionary<string, string> for this. The key of each value would be a field or info identifier: userFirstName, userAge, etc. As you process data you add it to your dictionary with whatever value you are reading.
When validating, you look up the stored value with the field identifier and compare it to whatever data shows upon your last page.
You can also consider using an enumeration as your key instead of string although if you avoid magic strings literals and use constants you should be ok.
Why can't you use the Contains() method saying
list.Contains(stringToCompare_1);
using Salesforce's enterprise wsdl I am trying to save opportunity line items along with opportunity. But I am getting following error:
INVALID_FIELD: No such column 'OpportunityLineItems' on entity 'Opportunity' If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
Here is my code to create line items:
if (oppLineItems.Count > 0)
{
sfOpportunity.OpportunityLineItems = new QueryResult();
sfOpportunity.HasOpportunityLineItem = true;
sfOpportunity.OpportunityLineItems.records = oppLineItems.Values.ToArray();
Pricebook2 priceBook = new Pricebook2();
priceBook.PricebookEntries = new QueryResult();
priceBook.PricebookEntries.records = new List<PricebookEntry>() { priceBookEntry }.ToArray();
sfOpportunity.Pricebook2 = priceBook;
}
oppLineItems is a dictionary whole values have proxy objects of opportunity line items.
sfOpportunity is proxy object of Opportunity which is then sent to Salesforce.
There's a very similar question here, not sure if we should mark it as duplicate though: Salesforce: Creating OpportunityLineItems as part of the Opportunity in PHP
OpportunityLineItems on Opportunity isn't a real field. Its something called "relationship name"... Similar to table alias in normal databases, useful especially when you're making joins. And HasOpportunityLineItem is a readonly field :) And I don't think these should be QueryResult, check http://www.salesforce.com/us/developer/docs/api/Content/sample_create_call.htm for some hints?
You will need to insert the Opportunity first, the operation result will give you the record's Id. Then you should insert a list (array) of the line items.
This means 2 API calls and extra considerations what to do when the Opp header saves OK but one or more lines fails... So maybe it's good idea to write an Apex webservice like I suggested in that other question.
I hope there is someone who can help me out here. I have found an article which gives you the short piece of code to add Add Multiple Entities (Members) to a Marketing List. So far so good. I'm coming across this problem. I have a custom lookup field which gets another marketing list (has contacts, accounts or leads) inside the marketing member list. Now I need to migrate (add) those members into my new marketing list. The code I have:
1. AddListMembersListRequest request = new AddListMembersListRequest();
2. request.ListId = Origmarketing_List_Id.Id;
3. request.MemberIds = new Guid[1];
4. request.MemberIds[0] = guid;
5. AddListMembersListResponse resp = (AddListMembersListResponse)service.Execute(request);
Line 2 is the ID I get from the EntityReference(Look Up field getting another Marketing List), now the third and fourth line I'm setting is something I'm really confused about but still I'm sure I'm going right here because I'm setting it to the listmemberid. In this example I just had one cause I wanted to try out how it works. The guid in line 4 bdw gets the right value, it is declared at the top of my code(and I have output it on another field just to check it grabs the right value). Also can someone please show how you would do this when you want to add multiple entities? Thanks. I'm registering my plugin on pre-operation(Create). And the plugin itself doesn't fire any errors, but it just doesn't seem to add any members on my new list. I would really much appreciate if somone could help me out here. Thank You Really Much in Advance.
First of all, change event to post-operation, because you don't have the GUID of created entity yet, as a matter of fact you dont have the entity itself as well that's why it's called pre-operation.
To add multiple entities try pass a GUIDs array like in code bellow:
// Setup the CrmConnection and OrganizationService instances
CrmConnectionInstance = new CrmConnection(ConfigurationConstants.CrmConnectionName);
OrgServiceInstance = new OrganizationService(CrmConnectionInstance);
// Create the marketing list
Guid NewMarketingListId = Guid.Empty;
Microsoft.Xrm.Sdk.Entity CurrentList = new Microsoft.Xrm.Sdk.Entity(MarketingListConstants.MarketingListEntityName);
CurrentList[MarketingListConstants.MarketingListTypeAttribute] = false;
CurrentList[MarketingListConstants.ListNameAttribute] = "NameOfList";
// For contacts, a value of 2 should be used.
CurrentList[MarketingListConstants.CreatedFromCodeAttribute] = new OptionSetValue(2);
// Actually create the list
NewMarketingListId = OrgServiceInstance.Create(CurrentList);
// Use the AddListMembersListRequest to add the members to the list
List<Guid> MemberListIds = new List<Guid>();
// Now you'll need to add the Guids for each member to the list
// I'm leaving that part out as adding values to a list is very basic.
AddListMembersListRequest AddMemberRequest = new AddListMembersListRequest();
AddMemberRequest.ListId = NewMarketingListId;
AddMemberRequest.MemberIds = memberIds.ToArray();
// Use AddListMembersListReponse to get information about the request execution
AddListMembersListResponse AddMemberResponse = OrgServiceInstance.Execute(AddMemberRequest) as AddListMembersListResponse;