Filter out users in a drop down on PCF - guidewire

In ClaimCenter I am trying to filter a drop down list to only display users that have a certain role. I am using a User input cell. There is no value range on the userinput cell only value. The value is set the user that they select so right now it's displaying all the users in the system instead of just the ones with the role that i want. Is there a way to show just the users that have the "Adjuster" role. I don't see a filter option either on this cell.

Right click the element and select "Change Element Type"
Then select "Range Input".
Then in the ValueRange property add a call to the code that you write.
The code to should find the subset of users that you want to show in the drop down and return them as a List or User[], something like this might work
function myValueRangeFunction(pClaim: Claim) : User[] {
//gets the group from the DB by public ID
var adjusterGroup = Group ("cc:123");
var adjustersOnly = new Set<User>();
var groupUsers = adjusterGroup.MembersNoSystemUsers
adjustersOnly.addAll(groupUsers*.Users)
return adjustersOnly.toArray()
}

You need to change the input type to Range Input (or Range Cell in case you are using List View) where valueRange property calls a method which retrieves users with a specific role.
.pcf file:
<RangeInput
editable="true"
id="userInput"
label=""Adjusters""
value="claim.AssignedUser"
valueRange="UserRoleUtil_Ext.Adjusters"
valueType="entity.User"/>
UserRoleUtil_Ext.gs:
uses gw.api.database.Query
uses gw.api.database.Relop
class UserRoleUtil_Ext {
public static property get Adjusters() : User[] {
var adjusterRole = Query.make(Role).compare(Role#Name, Relop.Equals, "Adjuster").select().AtMostOneRow
// Alternatively, you can retrieve the Role by its public-id, e.g.:
// var roleRetrievedById = Query.make(Role).compare(Role#PublicID, Relop.Equals, "cc:1").select().AtMostOneRow
return adjusterRole.AllUsersArray
}
}

Related

Where is my error with my join in acumatica?

I want to get all the attributes from my "Actual Item Inventry" (From Stock Items Form) so i have:
PXResultset<CSAnswers> res = PXSelectJoin<CSAnswers,
InnerJoin<InventoryItem,
On<CSAnswers.refNoteID, Equal<Current<InventoryItem.noteID>>>
>
>.Select(new PXGraph());
But, this returns me 0 rows.
Where is my error?
UPDATED:
My loop is like this:
foreach (PXResult<CSAnswers> record in res)
{
CSAnswers answers = (CSAnswers)record;
string refnoteid = answers.RefNoteID.ToString();
string value = answers.Value;
}
... but i can not go inside foreach.
Sorry for the English.
You should use an initialized graph rather than just "new PXGraph()" for the select. This can be as simple as "this" or "Base" depending on where this code is located. There are times that it is ok to initialize a new graph instance, but also times that it is not ok. Not knowing the context of your code sample, let's assume that "this" and "Base" were insufficient, and you need to initialize a new graph. If you need to work within another graph instance, this is how your code would look.
InventoryItemMaint graph = PXGraph<InventoryItemMaint>.CreateInstance<InventoryItemMaint>();
PXResultset<CSAnswers> res = PXSelectJoin<CSAnswers,
InnerJoin<InventoryItem, On<CSAnswers.refNoteID, Equal<Current<InventoryItem.noteID>>>>>
.Select(graph);
foreach (PXResult<CSAnswers> record in res)
{
CSAnswers answers = (CSAnswers)record;
string refnoteid = answers.RefNoteID.ToString();
string value = answers.Value;
}
However, since you should be initializing graph within a graph or graph extension, you should be able to use:
.Select(this) // To use the current graph containing this logic
or
.Select(Base) // To use the base graph that is being extended if in a graph extension
Since you are referring to:
Current<InventoryItem.noteID>
...but are using "new PXGraph()" then there is no "InventoryItem" to be in the current data cache of the generic base object PXGraph. Hence the need to reference a fully defined graph.
Another syntax for specifying exactly what value you want to pass in is to use a parameter like this:
var myNoteIdVariable = ...
InventoryItemMaint graph = PXGraph<InventoryItemMaint>.CreateInstance<InventoryItemMaint>();
PXResultset<CSAnswers> res = PXSelectJoin<CSAnswers,
InnerJoin<InventoryItem, On<CSAnswers.refNoteID, Equal<Required<InventoryItem.noteID>>>>>
.Select(graph, myNoteIdVariable);
foreach (PXResult<CSAnswers> record in res)
{
CSAnswers answers = (CSAnswers)record;
string refnoteid = answers.RefNoteID.ToString();
string value = answers.Value;
}
Notice the "Required" and the extra value in the Select() section. A quick and easy way to check if you have a value for your parameter is to use PXTrace to write to the Trace that you can check after refreshing the screen and performing whatever action would execute your code:
PXTrace.WriteInformation(myNoteIdVariable.ToString());
...to see if there is a value in myNoteIdVariable to retrieve a result set. Place that outside of the foreach block or you will only get a value in the trace when you actually get records... which is not happening in your case.
If you want to get deep into what SQL statements are being generated and executed, look for Request Profiler in the menus and enable SQL logging while you run a test. Then come back to check the results. (Remember to disable the SQL logging when done or you can generate a lot of unnecessary data.)

Hyperlink to page with smart search filter prepopulated

I have a smart search page that shows all the products on the page with some smart search filters that narrows down the products on some criterias (Let's say for example Filter1 has Option1, Option2 and Option3).
What I am trying to accomplish is to have a link on a seperate page that links to the product page, but when the user clicks on that link some of the search filters gets set (For example Filter1 would have Option2 selected).
I'm not sure if that is possible with out of the box solution, but with simple tweaks inside SearchFilter.ascx.cs, you can make a workaround. File is placed under CMSWebParts/SmartSearch/SearchFilter.ascx.cs. You should change method 'GetSelectedItems' to take a look into query string for filter value (see snippet bellow):
/// <summary>
/// Gets selected items.
/// </summary>
/// <param name="control">Control</param>
/// <param name="ids">Id's of selected values separated by semicolon</param>
private string GetSelectedItems(ListControl control, out string ids)
{
ids = "";
string selected = "";
//CUSTOM: retrive value for query string
var customFilter = QueryHelper.GetString("customFilter", "");
// loop through all items
for (int i = 0; i != control.Items.Count; i++)
{
//CUSTOM: ----START-----
if (!RequestHelper.IsPostBack())
{
if (!string.IsNullOrEmpty(customFilter))
{
if (control.Items[i].Text.Equals(customFilter, StringComparison.InvariantCultureIgnoreCase))
{
control.Items[i].Selected = true;
}
}
}
//CUSTOM: ----END-----
if (control.Items[i].Selected)
{
selected = SearchSyntaxHelper.AddSearchCondition(selected, control.Items[i].Value);
ids += ValidationHelper.GetString(i, "") + ";";
}
}
if (String.IsNullOrEmpty(selected) && (control.SelectedItem != null))
{
selected = control.SelectedItem.Value;
ids = control.SelectedIndex.ToString();
}
return selected;
}
And your hyperlink will look like this: /Search-result?searchtext=test&searchmode=anyword&customfilter=coffee
With this modifications, you can send only one value in filter, but if you need more then one value, you can send them and customize it however suits you best. Also, you can send filter name (in case that you have multiple filters) and then add check in method above.
I will recommend you not to modify kentico files. Instead of that, clone default filter web part and make modifications there, because withing next upgrade of project, you will lose your changes. I checked this in Kentico 11.
For Smart Search Filters:
if turn off auto-post back option -then web part control ID should become a query string parameter that you can use.
This above will form something like:
/Smart-search-filter.aspx?searchtext=abc&searchmode=anyword&wf=2;&ws=0;&wa=0
P.S. I suggest you to take a look at the corporate site example: look the smart search filter web part: /Examples/Web-parts/Full-text-search/Smart-search/Smart-search-filter. It is working example you can use it as starting point.

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

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

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; }
});

Dynamically Selection of items in combobox

i want to add some functionality in combo box. I want that it should behave like Google's Search Box. Like i have added items in combo box from a database Say Name of the Doctors.
i want that as user type name of the doctor or first letter of the name of the doctor, the selection bar goes automatically only to related names.
Any suggestion friends???
try AutoCompleteMode of combobox, something like this:
сomboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
сomboBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
comboBox.AutoCompleteCustomSource = MyStringData();
where myStringData is :
public AutoCompleteStringCollection MyStringData()
{
var collection= new AutoCompleteStringCollection();
//you can add names of the doctors retrieved from the database here
collection.Add("one");
collection.Add("two");
collection.Add("three");
collection.Add("four");
return collection;
}
this would suggest those items which begins with those you typed.
If you want to show selection (highlighting) as you type, you can be a little more creative and create a simple combination of a textbox and gridView, which gets bound everytime TextChanged happens on the textBox

Resources