I have a C# MVC4 application in which I am writing a JQuery function to grab some values, post to an ActionResult and then refresh a partial view. All functionality is working except for setting a new var equal to the value of a variable within one of my div elements.
The pre-existing variable is called myName and is located in a div with an id of NameDiv.
Ive tried these four versions of code and each results in: Reference Error myName is not defined.
var origname = myName;
var origname = myName.value();
var origname = myName.val();
var origname = $('#NameDiv').valueOf(myName);
When running the application and inspecting element, I see that myName is populating with the correct value.
Use:
var origname = $('#NameDiv').find('input[name="myName"]').first().val();
// console.log(origname);
This will find the element on the page with the id of "NameDiv". Then it gets the input elements on the page with the name of "myName". Then it gets the first one found. It will then get the value of it (by using .val()), and store that value in the variable origname.
Related
When I try to create a new list item with the basic calendar/list fields everything works perfectly. However, when I try to do so with a "non-standard" field i.e. a field I added, I am getting a "field not recognized" error.
The field is clearly there! Is there some special way I need to populate these custom fields?
// get a specific list
ISiteListsCollectionPage list = await graphClient.Sites["root"].Lists.Request()
.Filter($"DisplayName eq 'Outlook Integration'").GetAsync();
// create a dictionary of [calendar] list properties
Dictionary<string, object> props = new Dictionary<string, object>();
// populate properties, all of these work just fine
props.Add("Title", evt.Subject);
props.Add("Location", evt.Location?.DisplayName);
props.Add("EventDate", utcStart.ToString("yyyy-MM-ddTHH:mm:ssK"));
props.Add("EndDate", utcEnd.ToString("yyyy-MM-ddTHH:mm:ssK"));
props.Add("Description", Regex.Replace(evt.Body.Content, "<.*?>", String.Empty)); // remove HTML content
// populate custom properties
props.Add("ResourceID", evt.Id); // throws error: Field 'ResourceID' is not recognized
// create list item with our properties dictionary
var newItem = new ListItem
{
Name = "My New Event",
Fields = new FieldValueSet()
{
AdditionalData = props
}
};
// call the service and get the result
var newListItem = await graphClient.Sites["root"].Lists[list[0].Id].Items.Request().AddAsync(newItem);
This is the complete list of fields on my list:
Here you can see the display name is "ResourceID" whereas the API name is "O365EventId." However, both result in the same error, "Field not recognized."
Note: ResourceID is one of the fields that I added. How can I set the value of this field via the Graph API?
Marc is right by saying in comment regarding column name, the provided screenshot displays Column.displayName which is
The user-facing name of the column.
but what actually FieldValueSet.AdditionalData expects as a key is Column.name which is:
The API-facing name of the column as it appears in the fields on a
listItem. For the user-facing name, see displayName.
In your case most likely displayName and name properties are different, you could verify it via following endpoint:
https://graph.microsoft.com/v1.0/sites/root/lists/Outlook Integration/columns
and that's the reason why this error occurs.
Via the Graph API client (C#), you can see a list of all columns for any given list like so:
// get specific list by name
ISiteListsCollectionPage list = await graphClient.Sites["root"].Lists.Request()
.Filter($"DisplayName eq 'YOUR_LIST_NAME_HERE'").GetAsync();
// get columns and output them to the log as a serialized object
var listColumns = await graphClient.Sites["root"].Lists[list[0].Id].Columns.Request().GetAsync();
logger.LogInformation($"List Columns Object: {JsonConvert.SerializeObject(listColumns).ToString()}");
I have a bunch of divs. I am looping thru them using their class name: col-lg-3. In each of the divs by the class name above, I have xpaths like the ones below. I need to pick out the string value at td[4]
.//*[#id='item-186951']/div[1]/table/tbody/tr[6]/td[4]
.//*[#id='itemPNS18-152951']/div[1]/table/tbody/tr[6]/td[4]
.//*[#id='itemXYZ-8152951']/div[1]/table/tbody/tr[6]/td[4]
.//*[#id='item11641551']/div[1]/table/tbody/tr[6]/td[4]
.//*[#id='itemAPS12641']/div[1]/table/tbody/tr[6]/td[4]
This part is the one that is changing in every element [#id='{dynamically-changing-id}'], with the rest being constant. How do I loop over this? At the moment I am trying this but I only get the first item (understandably)
//get all divs on page
var elements = ...FindElements(By.ClassName("col-lg-3"));
//for each div found
foreach(var e in elements)
{
//get text at xpath
string str = e.FindElement(By.XPath(".//*[#id='item-186951']/div[1]/table/tbody/tr[6]/td[4]"));
}
Im using Selenium 2.53
You can check that id attribute starts with "item":
var elements = ThisPage.FindElements(By.XPath(".//*[starts-with(#id, 'item')]/div[1]/table/tbody/tr[6]/td[4]"))
I have a aspxcombobox with ID="comboSubjectCategory", can I get the selected value/text using javascript function? thanks lot...I tried this but it does not works.
function getValue() {
var combo = document.getElementById('comboSubjectCategory').value;
alert(combo);
}
The ASPxComboBox is not a simple HTML element. In the browser, it is represented by the ASPxClientComboBox Class. Use its GetValue, GetText or GetSelectedItem methods to obtain the selected value.
You can obtain the ASPxClientComboBox instance by the name assigned to the ClientInstanceName property of the ASPxComboBox control.
See Also: Client-Side Functionality
var combo = document.getElementById('<%= comboSubjectCategory.ClientID %>');
var val = combo.options[combo.selectedIndex].value;
Is this the best way to get the parentId of a page from the IPageStructure in Composite C1 within a UserControl ?
string pPageId = SitemapNavigator.CurrentPageId.ToString();
Guid parentId = connection.Get<IPage>().Where(p => p.Id == new
Guid(pPageId)).First().GetParentId();
I do use the present pageId as a string, which helps in the above case seeing as .First() can't be used on Guid.
Take a look at the SitemapNavigator instance class you can grab from DataConnection - when you get the data bound instance it gives you access to the current page in form of a PageNode class from which you can access parent, child pages. You also have access to titles, descriptions etc.
// General (verbose) example - getting parent page ID
using (var connection = new DataConnection())
{
var currentPageNode = connection.SitemapNavigator.CurrentPageNode;
var parentPageNode = currentPageNode.ParentPage;
var parentPageId = parentPageNode.Id;
}
If you are doing this from a Razor Function there is already a data connection available (this.Data) so the above can be written like this:
// Razor example - getting parent page ID
var parentPageId = Data.SitemapNavigator.CurrentPageNode.ParentPage.Id;
One option is just to rely 100% on the standard asp.net way using the SiteMapProvider functionality.
Get a specific node like this: var node = SiteMap.CurrentProvider.FindSiteMapNodeByKey("...").
Get the Parent node like this: var parentNode = node.ParentNode.
Get its id like this: var id = parentNode.Key
how can I insert a document inside another document with mongodb ?
I've tried something like the code below but I always have a problem converting my list of setting in the field Settings:
var settingViewModels = new[]{ setting };
var query = Query.EQ("Name", applicationName);
var update = Update.AddToSet("Settings", BsonArray.Create(setting));
db.Collection<Applications>().Update(query, update, UpdateFlags.Upsert, SafeMode.True)
I got an error when I convert my settingViewModels into BsonArray saying:
.NET type MyProject.SettingViewModel cannot be mapped into BsonType.Array
Parameter name: value
Any idea ?
thanks
John
If you want add setting item to the Settings[] array of Application collection you should use ToBsonDocument() extention method from MongoDB.Bson namespace:
var update = Update.AddToSet("Settings", setting.ToBsonDocument());
You no need create BsonArray.