Set webpart visibility based on page category in Kentico - kentico

I have a page with a static HTML web part and want to set its visibility based on the value of the page category. If the category = "ABC" then make it visible, if not make it invisible. The category value was set through the Properties tab. I've tried these 2 macro below, but both didn't work. Thanks for your help!
{%if(CurrentDocument.Categories.DisplayNames=="ABC"){ return true; } else { return false; } #%}
or
{%if(CurrentDocument.Categories.DisplayNames.Contains("ABC")){ return true; } else { return false; } #%}

You can do it with the following macro (and there is no need for IF condition):
{% CurrentDocument.IsInCategories("ABC;ABCD") %}
Multiple categories can be listed with a semicolon.

Related

Hiding value of a selector in a grid dynamically

I am trying to hide these duplicate inventory ID values for the "price" and "Cost" lines (when one "adds" an item to the grid it creates three lines), but the selector description still appears.
How can I just make these value come up blank in the grid?
Even better, how can I disable a link command so if someone inadvertently clicks then it wont link to the stock item screen?
Here is my code thus far:
protected void _(Events.FieldSelecting<FPPriceSheetDetail, FPPriceSheetDetail.inventoryID> e)
{
if (e.Row is null) return;
if (e.Row.RowType == FPPriceSheetRowType.BreakQty) return;
var state = PXFieldState.CreateInstance(e.ReturnState, typeof(string), true, false, 1, null, null, null, nameof(FPPriceSheetDetail.inventoryID));
state.SelectorMode = PXSelectorMode.TextMode;
state.DescriptionName = "";
state.ValueField = "";
state.Visibility = PXUIVisibility.Visible;
state.Visible = true;
e.ReturnState = state;
e.ReturnValue = "";
}
I would rather review the pxSelector and in the condition only show 1-row type - this will remove the duplicates. The point of the selector is to select one of the values within the result - assuming all the information the selector are selectable.

Property for PXProcessing row

I have a processing page that I want to automatically select certain types of rows. I can set the select checkbox to true, but what property needs to be set on the row so that the process button will act on it? Right now nothing happens unless I check another row.
public void EDASNShipProj_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
PXUIFieldAttribute.SetDisplayName<EDASNShipProj.customerLocationID>(sender, "Ship Location");
var row = (EDASNShipProj)e.Row;
if ( row.UsrTruckNbr != 0 )
row.Selected = true;
PXUIFieldAttribute.SetVisible<SOShipment.selected>(sender, null, true);
}
I figured this out after searching the base source code for ".Selected=true". I found several places which included two extra lines. I added them to my condition and now the checked rows are included in the process list. Hopefully this will help others.
if (row.UsrTruckNbr != 0)
{
row.Selected = true;
sender.IsDirty = true;
sender.SetStatus(row, PXEntryStatus.Updated);
}

TWIG: Get the first item fulfilling a condition

I need to display the first item that fulfills some condition. Something I would normally do via construction like this pseudocode:
for(item in some_array)
if(some_condition(item)) {
some_action();
break;
}
The problem is I need to do that in TWIG and TWIG does not allow to break a for loop. How to do that then?
You could use a boolean to denote that you have processed the first item but it will continue to loop over the rest of the array:
set firstItemProcessed = false;
for(item in some_array) {
if(firstItemProcessed == false and some_condition(item) ) {
some_action();
firstItemProcessed = true;
}
}

Approve Time Card Summaries filter customization

I'm customizing the Approve Time Card Summaries screen to do the following:
1.) Add a checkbox to the filter section
2.) When this checkbox is checked, don't show the 'Approved' rows in the grid.
I've added a cache extension with a new unbound boolean field, and added the checkbox to the filter / header section of the screen.
What I'm wondering is - Is there an IEnumerable method (can I use 'summary'?) that can check that header filter field and only yield return the rows that pass the filter test? If so, I'm not sure what the syntax would be to do this.
Or - would it be better to rewrite the Summary view select statement in the Graph extension with the added where clause?
Thanks...
I figured out how to do this. In the Graph extension, I rewrote the 'Summary' view and then used the IEnumerable 'summary' delegate to return only the rows where it meets the checkbox criteria I set up. To wit:
public PXSelectJoin<EPSummaryApprove
, LeftJoin<EPEarningType, On<EPEarningType.typeCD, Equal<EPSummaryApprove.earningType>>>
, Where2<Where<EPSummaryApprove.taskApproverID, Equal<Current<EPSummaryFilter.approverID>>, Or<Where<EPSummaryApprove.taskApproverID, IsNull, And<EPSummaryApprove.approverID, Equal<Current<EPSummaryFilter.approverID>>>>>>
, And2<Where<EPSummaryApprove.weekId, GreaterEqual<Current<EPSummaryFilter.fromWeek>>, Or<Current<EPSummaryFilter.fromWeek>, IsNull>>
, And2<Where<EPSummaryApprove.weekId, LessEqual<Current<EPSummaryFilter.tillWeek>>, Or<Current<EPSummaryFilter.tillWeek>, IsNull>>
, And2<Where<EPSummaryApprove.projectID, Equal<Current<EPSummaryFilter.projectID>>, Or<Current<EPSummaryFilter.projectID>, IsNull>>
, And2<Where<EPSummaryApprove.projectTaskID, Equal<Current<EPSummaryFilter.projectTaskID>>, Or<Current<EPSummaryFilter.projectTaskID>, IsNull>>
, And<Where<EPSummaryApprove.employeeID, Equal<Current<EPSummaryFilter.employeeID>>, Or<Current<EPSummaryFilter.employeeID>, IsNull>>
>
>
>
>
>
>
> Summary;
protected IEnumerable summary()
{
var epsf = (EPSummaryFilter)Base.Filter.Cache.Current;
var epse = PXCache<EPSummaryFilter>.GetExtension<EPSummaryFilterExt>(epsf);
foreach(var res in Base.Summary.Select())
{
var sum = (EPSummaryApprove)res;
if (epse != null)
{
if (epse.ExcludeApproved == true)
{
if (sum.IsApprove != true)
{
yield return res;
}
}
else
yield return res;
}
else
yield return res;
}
}

Disable an outputlink coming from database based on condition

I am developing an app where I have come across at the condition where I am fetching some links from database, based on those links more retrieval is being done. I want to disable the outputlink if there is an empty row retrieved based on this outputlink.
I am swtting preRequisiteNull with boolean result and rendering the outputlink in primefaces but it disappear when if only one row have true value.
My Code:
for(LabOrdersDTO laborderDto:labOrdersDTOListDataModel.getWrappedData())
{
System.out.println("Speciman Name"+laborderDto.getTest());
System.out.println(laborderDto.getLabNo());
for(LabOrdersDTO laborderDto2:labTestPreReqList.getWrappedData())
{
System.out.println("Lab test"+laborderDto2.getTest());
if(laborderDto2.getTestPreReq()!=null){
preRequisiteNull = false;
}else{
preRequisiteNull = true;
}
}
}
if i understand you correctly, then your mistake is in your for-loops.
you want to disable link if one link = null ? right?
if yes then you have to breake the loop if one link is null, otherwise the next notNull link will override the value.
replace this:
for(LabOrdersDTO laborderDto:labOrdersDTOListDataModel.getWrappedData())
{
for(LabOrdersDTO laborderDto2:labTestPreReqList.getWrappedData())
{
if(laborderDto2.getTestPreReq()!=null){
preRequisiteNull = false;
}else{
preRequisiteNull = true;
}
}
}
width this :
for(LabOrdersDTO laborderDto:labOrdersDTOListDataModel.getWrappedData())
{
for(LabOrdersDTO laborderDto2:labTestPreReqList.getWrappedData())
{
if(laborderDto2.getTestPreReq()==null){
preRequisiteNull = true;
// update the link state or no idea how you manage it to disable the link
break;
}
}
}
BUT i cannot see how you set the link state to be disabled. my suggestion will break if one row is empty, but you have to update the state of that link!

Resources