I have two document types:
FormSubmission
FormField
The Form document type has a property named Fields which is a Nested Content data type that contains a list of FormField document types. I am trying to programmatically (in a SurfaceController) create a FormField and add it to the Fields property of the Form document type.
Here is the code I am trying to use to do this:
var newFormFields = new List<Umbraco.Core.Models.IContent>();
int i = 0;
foreach (var formField in model.Fields)
{
string fieldName = string.Format("Field {0}", i);
var newFormField = contentService.CreateContent(fieldName, newFormSubmission.Id, "formFieldSubmission", formNode.CreatorId);
newFormField.SetValue("fieldName", formField.Name);
newFormField.SetValue("fieldType", formField.Type);
newFormField.SetValue("manditory", formField.Manditory);
newFormField.SetValue("fieldValue", formField.Value);
newFormFields.Add(newFormField);
++i;
}
newFormSubmission.SetValue("fields", newFormFields);
var status = contentService.SaveAndPublishWithStatus(newFormSubmission, formNode.CreatorId, raiseEvents: false);
On the newFormSubmission.SetValue("fields", newFormFields); line it throws this exception:
The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments
Anyone have any ideas how to store a list of DocumentTypes in the Nested Content data type?
PS: I am using Umbraco version 7.4.0 assembly: 1.0.5885.31226
UPDATE:
Lee Kelleher pointed me in the right direction towards developing my own solution in this post on the umbraco forms. I hope to have time after this project to polish up my solution and submit a pull request to the project.
I basically ended up creating some extension methods that take an IEnumerable<IContent> and return a JSON representation of the objects for the NestedContent plugin.
This gist might help you:
robertjf/NestedContentCreator.cs
There's an example in the second file further down. It was written last year and may require some tweaking; but it should give you a good start.
It seems that the second argument of the SetPropertyValue method expects a string and you are passing a List<Umbraco.Core.Models.IContent>
Related
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.
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);
Hey I trying to update existing document of ElasticSearch, I found a cURL code from Elasticsearch site
Note: Sam type with 2 document is already exists I just want to update a existing field
POST /EmployeeIndex/Sam/2/_update
{
"doc" : {
"Nested" : true,
"views": 0
}
}
Its working perfectly how I need but please help me to convert it to NEST, as i working on .NET, I managed to write a code
var responseUpdate = client.Update<clsEmployeeElasticSearch, object>(u => u
.Index("EmployeeIndex")
.Type("Sam")
.Id(2)
.Doc(new { Nested= true })
.RetryOnConflict(3)
.Refresh());
But it always creating a new field in my document instead of updating existing one.
Please see attached screenshot with a code
Please help guys.
What you need is a PartialUpdate. Applied on your example, the following code should do what you expect.
var responseUpdate = client.Update<clsEmployeeElasticSearch, object>(u => u
.Index("EmployeeIndex")
.Type("Sam")
.Id(2)
.Doc(new {IsActive ="true", Views="0"})
.DocAsUpsert()
);
Is it possible that you are already there but be just facing a casing missmatch issue? see from Nest reference:
Property Name Inference In many places NEST allows you to pass
property names and JSON paths as C# expressions, i.e:
.Query(q=>q
.Term(p=>p.Followers.First().FirstName, "martijn")) NEST by default will camelCase properties. So the FirstName property above
will be translated to "followers.firstName".
This can be configured by setting
settings.SetDefaultPropertyNameInferrer(p=>p); This will leave
property names untouched.
Properties marked with [ElasticAttibute(Name="")] or
[JsonProperty(Name="")] will pass the configured name verbatim.
...
Note that you are creating a dynamic object for the update so, i belive attributes might not a be a solution if you keep it that way
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 have a RelatedLinks property in one of my pages that I need to get the links/PageIds out from in the code behind of my macro-user control.
I can get the property like this
var current = Node.GetCurrent();
Response.Write("Output: " + current.GetProperty("RelatedLinks").Value);
But the output is empty. When I debug I can see that the Value includes some list content (like tags and such) some somehow nothing is printed.
My question is how I can get the value from this property into something like a collection of hyperlink objects.
I'm new to Umbraco and I's possible that I'm missing something essential here. Getting the content of other property types (like the Content Picker) works fine.
Thanks!
You can use this simple solution in Umbraco 7.+
Model.Content.GetPropertyValue<Umbraco.Web.Models.RelatedLinks>("relatedArticles");
this simply convert data to static type that is easy to use.
What data type is your related links set to, assuming its a content picker where you are getting the id of the related page you could first create a node form your current page's id then try and get the value from that node e.g.
var current = Node.GetCurrent();
var currentPage = Model.NodeById(current.Id);
var relatedLinks = currentPage.RelatedLinks;
or
var relatedLinks = GetProperty("RelatedLinks").Value;
when you debug you should be able to see all the properties of currentpage and check your alias as well to make sure its right (generally aliases dont start with a capital by default).
Try this umbraco.NodeFactory.Node.GetCurrent().GetProperty("RelatedLinks")
Solved it like this:
Document doc = new Document(Node.GetCurrent().Id);
umbraco.cms.businesslogic.property.Property relatedLinks = doc.getProperty("RelatedLinks");
XmlNode relatedLinksAsXml = relatedLinks.ToXml(new XmlDocument());
However it says that the Document class is obsolete and wants me to use Umbraco.Core.Models.Content instead. But this is MVC right? I'm trying to use webforms. Tried using the Node class as described in this thread but the Property object I got returned was of the wrong type and couldn't be converted to XML.