Access List Options for a Field in a Custom Table in Kentico 10 - kentico

I have a custom table with a few fields that have list options for the user to select from when adding the content. Is there something in the API that allows me to access the options for a particular field so I can use those same options in a filtering widget?
Something like the below but that works for fields in a custom table?
var guids = ParentDocument.GetValue("CustomFieldName").Split(';');
var referencedDocs = DocumentHelper.GetDocuments().WhereIn("DocumentGuid", guids);
UPDATE - The code in case the link in the answer changes:
protected string[] GetFormFieldOptions()
{
DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo("custom.MyPageTypeName");
if (dci != null)
{
//Get the data from the form field
FormInfo fi = new FormInfo(dci.ClassFormDefinition);
FormFieldInfo ffi = fi.GetFormField("Industry");
string[] industries = ffi.Settings["Options"].ToString().Split('\n');
return industries;
}
return null;
}

Use DataClassInfoProvider in order to get data you need. Check this blog post to see more details.

You can use the same code as you have in your question. The difference is you need to get 2 different things which are not available at the "Page" or "Document" level:
Custom table object
Custom table item based on #1
You use the API to get the custom table item:
var cti = CustomTableItemProvider.GetItem(<id or guid>, "yourcustom.tableclassname);
if (cti != null)
{
string[] s = ValidationHelper.GetString(cti.GetValue("YourField"), "").Split(";");
}
Update
To get a dynamic list of options in a field you can simply use a listing control like a dropdown list or a radio button list as your control (vs. a textbox). Then in the properties for the dropdownlist, you can set it to a query. In the query enter something like
-- if you wan to have a 'select one' add this
SELECT '', '-- select one --'
UNION
SELECT ItemID, FieldName
FROM CustomTable_Name
ORDER BY 2

Related

How to get source list types of particular list/record field?

Here is I have two entity custom fields with list/record type,
custom_dev_j15 entity field has a custom source list (eg: one, two, three, four, etc)
custom_qa_v93 entity field has a standard source list as an object (eg: customer )
I've two vendor entity custom fields as stated in screenshots of question,
custentity473 --> customer is selected as list source
custentity474 --> custom_dev_j15_m_list as selected as list source ( which is custom list)
Here is snippet that i used to get the options of these fields,
// Snippet
var fieldDetails = {};
var record = nlapiCreateRecord("Vendor");
var field = record.getField("custentity473");
var selectoptions = field.getSelectOptions();
for ( var i in selectOptions) {
var Option = {
id : selectOptions[i].getId(),
label : selectOptions[i].getText()
}
Options.push(Option);
}
fieldDetail["options"] = Options;
But my need is to get source list information like name of the list source (customer or custom_dev_j15_m_list) via suitescript
any idea on how to get this information?
Thanks in advance
I'm not sure I understand this question for what you're trying to do.
In NetSuite almost always, you accommodate to the source list types because you know that's the type, and if you need something else (e.g. a selection which is a combination/or custom selection you'll use a scripted field)
Perhaps you can expand on your use case, and then we can help you further?

Select UI Element by filtering properties in coded ui

I have a web application. And I am using coded ui to write automated tests to test the application.
I have a dropdown with a text box. Which on entering values in the textbox, the values in the dropdown gets filtered based on the text entered.
If I type inside textbox like 'Admin', I will get below options like this:
And I need to capture the two options displayed.
But using IE Developer tool (F12), I am not able to capture the filtered options, because the options that are displayed do not have any unique property (like this below). And the options that are NOT displayed have a class="hidden" property
Any way to capture the elements that are displayed by applying some kind of filter like 'Select ui elements whose class != hidden'
Thanks in advance!!
HI please try below code will it works for you or not.By traversing all those controls that have class ="hidden"
WpfWindow mainWindow = new WpfWindow();
mainWindow.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
UITestControlCollection collection = mainWindow.FindMatchingControls();
foreach (UITestControl links in collection)
{
HtmlHyperlink mylink = (HtmlHyperlink)links;
Console.WriteLine(mylink.InnerText);
}
I'm not sure there is a way to do it by search properties, but there are other approaches.
One way would be to brute force difference the collections. Find all the list items, then find the hidden ones and do a difference.
HtmlControl listControl = /* find the UL somehow */
HtmlControl listItemsSearch = new HtmlControl(listControl);
listItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
HtmlControl hiddenListItemsSearch = new HtmlControl(listControl);
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
var listItems = listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
You will only be able to iterate this collection one time so if you need to iterate multiple times, create a function that returns this search.
var listItemsFunc = () => listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
foreach(var listItem in listItemsFunc()){
// iterate 1
}
foreach(var listItem in listItemsFunc()){
// iterate 2
}
The other way I would consider doing it would be to filter based on the controls which have a clickable point and take up space on the screen (ie, not hidden).
listItemsSearch.FindMatchingControls().Where(x => {
try { x.GetClickablePoint(); return x.Width > 0 && x.Height > 0; } catch { return false; }
});

create a filter not a group filter

I am creating a custom module in Orchard , I would like to create a query programmatically.
string queryName= "Product";
var item = _orchardServices.ContentManager.New("Query");
item.As<TitlePart>().Title =queryName;
_orchardServices.ContentManager.Create(item, VersionOptions.Draft);
if (!item.Has<IPublishingControlAspect>() && !item.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable)
_orchardServices.ContentManager.Publish(item);
var queryPart = item.As<QueryPart>();
queryPart.ContentItem.ContentType = queryName;
string desc =" filter for the query";
string contentType = "CommonPart.ChannelID.";
var filterGroupRecord = new FilterGroupRecord();
var filterRecord = new FilterRecord()
{
Category = "CommonPartContentFields",
Type = contentType,
Position = 0,
};
filterRecord.State = "<Form><Description>" + desc + "</Description><Operator>Equals</Operator><Value>ChannelId</Value></Form>";
filterGroupRecord.Filters.Add(filterRecord);
queryPart.FilterGroups.Insert(0, filterGroupRecord);
the problem is that:I want set a filters of the query,not a filters group.
could you tell me how to improve my code?
Database structure and class declarations make it impossible. Why do you need it?
Update:
I means that you must use FilterGroupRecord at least one.
But when Query published that Filter Group will be created automatically if query have not yet Filter Group (see at QueryPartHandler). You should add your filters to this group. And not needed to create new group.
var existingFilterGroup = queryPart.FilterGroups[0];
existingFilterGroup.Filters.Add(filterRecord);
Update 2:
To avoid problems with draftable query (and several other potential problems Orchard CMS: Adding default data to fields and then querying them) it is better to move the calling Publish method to the end of your code and other part of your code should be left unchanged. And in your case would be better if you will always publish your query without checking IPublishingControlAspect and Draftable.

Sharepoint webpart combobox of lists

I have a webpart that works off of a list but what I'm trying to do create a dropdown that contains a list of sharepoint lists so that when the user edits the page and selects 'modify shared webpart' they are able to choose a list item and that gets parsed back to the webpart.
Any examples or links to examples appreciated!
Thanks
Dan
What you are looking for is called a Toolpart. Take a look at this example for a tutorial on how to create one.
Overall, your general steps will be:
Create your custom Toolpart class inheriting from Microsoft.SharePoint.WebPartPages.ToolPart
In your custom Toolpart, override CreateChildControls, write the code to iterate over the lists in your SPWeb, and add those to a DropDownList
In your webpart, override GetToolParts and add your custom ToolPart so that it shows up in the right hand side
It sounds like you want to create a custom editor part. In the part you would have one dropdown that shows the names of the lists (you probably want to filter hidden and empty lists) and, when an item is selected from the list, a second dropdown shows the Title column of the items from the selected list.
Here's some code (edited here, so it will need to be cleaned up) to help you get started:
protected Page_Load(...)
{
if (IsPostBack) return;
var web = SPContext.Current.Web;
var query = from list in web.Lists
where list.Hidden == false && list.ItemCount == 0
select list;
DropDownList1.DataSource = query;
DropDownList1.DataTextField = "Title";
DropDownList1.DataBind();
}
protected DropDownList1_SelectedIndexChanged(...)
{
var web = SPContext.Current.Web;
var listName = DropDownList1.Text;
var list = web.Lists[listName];
var table = list.Items.GetDataTable();
DropDownList2.DataSource = table;
DropDownList2.DataTextField = "Title";
DropDownList2.DataValueField = "ID";
DropDownList2.DataBind();
}

Sharepoint Custom List with TimeStamp Field

I'm making a custom SharePoint List. I need a TimeStamp Field, but the only available type, by default, is DateTime.
Any help?
I think you would need to create a custom field type so that you can control the display of a DateTime type and validation etc - see this blog post for more info
I had the same problem in Sharepoint 2010 and solved it. Posting in case someone else finds this useful :)
To achieve this one must use the "Calculated" columntype.
From GUI:
Create new column
Pick type "Calculated".
Select "Created" column and add to formula.
Save.
From code:
As far as I can tell, there is two options to achieve this:
Access the "Created" and either set it's ShowInDisplayForm property to true or add the column to a view (for example the DefaultView).
Create a calculated column that points to the "Created" column, just as the GUI-example does. The trick is to set the "Formula" & the "OutputType" properties.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.RootWeb)
{
SPList list = web.Lists["test"];
string fieldName = list.Fields.Add("Timestamptest", SPFieldType.Calculated, false);
SPFieldCalculated field = list.Fields[fieldName] as SPFieldCalculated;
field.Formula = "=Created";
field.OutputType = SPFieldType.DateTime;
field.ShowInEditForm = false;
field.Update();
list.Update();
SPView defaultView = list.DefaultView;
defaultView.ViewFields.Add(field);
defaultView.Update();
}
}
});

Resources