In Oracle APEX, is it possible to create a validation so that field B cannot be null if a "Modem" is selected in field A? (field A is a Select List that contains a List of Values that uses a query to receive it's list of values)
Thanks Tony,
Your solution makes sense but it didn't work in my case.
Here is my validation:
The result is not what I expected. I would like an error only to show up for "Unit Ip Address" when Modem is the selected Device Type when the field is null.
Additional Info that describes the "Device Type":
Yes - see this example, where field Commission cannot be null if "Salesman" is selected in field Job.
It is simply a "Not Null" validation on item P15_COMMISSION, with a condition to perform the validation only when P15_JOB has the value "Salesman"
This is the validation definition I used:
Note that the condition on the validation is based on the return value of the LOV, not the display value. In my case they happen to be the same, but in yours they are not and your condition should be based on the ID of the device type rather than the description.
Related
I have an item to enter the email ids item_email
I need to give validation for email id item item_email that the email id should not exists already in table.
So I have to create email validation please help me to proceed on this.
You need to create a Validation (Processing tab) with type No Rows Returned, and put the following to the validation query:
select 1
from table_with_emails
where email_column = :P_EMAIL_ITEM
UPD
To check email: create a new validation (it is easier than add two checks in one) with type PL/SQL Expression, and add the following:
regexp_like (:P_EMAIL_ITEM, '^[A-Za-z]+[A-Za-z0-9.]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$')
Creating a new validation also allows you to define two different error messages: when email is already exists and when it has wrong format.
Additionally, consider creating UNIQUE INDEX on e-mail column. Apex validation would do the job, but won't prevent another ways of inserting data.
I'm trying to make a poll results page with the results from a WFFM form. I initially took all the entered data(using AnalyticsFormsDataProvider), queried it, and then displayed the results. However, if no one votes for a particular answer, it wouldn't be in the entered data so it wouldn't show.
I want to display that the field had 0 votes, so now I'm trying to compare the possible answers to the queried list. However, I can't seem to find a way to access the values of the list items. Does anyone know the class those values are stored in and/or how to access them?
I'm using WFFM 8.1 rev. 151217 (Update-1) with MVC. It's a radio list field if that makes a difference from the other list fields.
Thanks,
You are able to get WFFM field as regular Sitecore item via standard API.
Available list items values are saved in "Parameters" and "Localized Parameters" fields. You can use Sitecore.Form.Core.Utility.ParametersUtil from Sitecore.Forms.Core to parse values saved in these fields.
This data is stored on your Radio List Field's Item in the fields Parameters and Localized Parameters.
If your code is within the Form's SaveAction or a Validator you will have access to the Field in the for AdaptedResultList args the SaveAction or via this.classAttributes["fieldid"] for the Validator. That will be enough for you to get the Radio List Item and then the Parameter fields.
If your code is not in a SaveAction / Validator I recommend passing the Form Item into your code possibly by Datasource and then retrieving the Radio List Item from that.
Finally the Items of the your Radio List field is stored in the format
<item><item>
If your radio items are actually items you will want to parse them using a regex
var regexItems = new Regex(#"<item>(.*?)</item>".ToLower());
var itemNodes = regexItems.Matches(FieldItem["Parameters"].ToLower());
Then you should be free to play with the list for your poll
In my template I have a field type of Droplist which maps to a Sitecore folder holding values for the Droplist which in this case is Colours. This is so that an editor cannot make a typo or invent a colour this is not in the pre-defined list.
So that colour is based off a template I call TAGS which has a single field type of 'colour' and here I create a series of items using that template to create the colours for the swatch list.
When I access the main template I duly see the colour values in that Droplist so its working as I would expect it because I can access that fields values:
tileValues.Attributes["class"] += " tile-" + Item.Fields["Tile Colour"].Value.ToLower();
However I have realized its not using the field value of the template but rather the name I have called the item. SO its just a happy mistake that its achieving the result I wanted.
However how would I obtain the actual field value for that item in the end code. I have scenarios where there will be multi lingual editors so we may name the tags as rouge, blanc etc which is what the editor will see on selection in the Droplist but we need the colour value of the field to still say red or white etc
I tried:
Item.Fields["Tile Colour"].Item.Fields["Colour"].Value
But this failed despite the API hint implying its valid.
I hope this makes sense and someone can help me obtain the actual field value and not the items name.
As Sitecore Climber wrote, don't use Droplist field type - it stores item name only and you cannot get the item itself in the code behind.
Use Droplink field type - it stores ID of the item.
Then you can get the item:
Item colourItem = Sitecore.Context.Database.GetItem(Item["Tile Colour"]);
if (colourItem != null)
{
string colour = colourItem["Colour"];
|
I have two fields that run throughout a website that I would like to match so that when a user inputs a value either of the fields, it will match the other field. I'm using Sitecore Rocks and am trying to use a query to do this.
select ##h1#, ##Title#
from /sitecore/Content/Home//*[##h1# !="##Title#"];
update set ##h1# = ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
What am I missing here?
This article talks about tapping in to the item:saving event which allows you to compare the fields values of the item before and after the changes:
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Intercepting-Item-Updates-with-Sitecore.aspx
Using this, you can determine which field has been amended, then change the other to match.
I've had to do something similar to this when a new field was added, and we wanted to set the initial value equal to an existing field. It may be a bug in Sitecore Rocks, but I found it would only update a field when a static value was part of the query.
When I ran ##h1# = ##Title#, the query analyzer would return the correct number of items updated, but no values were actually updated. However, ##h1# = '<id>' worked perfectly. After trying a number of things, I found this did what I wanted.
update set ##h1# = '' + ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
I hope that helps.
I have a use case in which users need to select a field value from a droplist of items. The problem with this is that the droplist needs to be dynamically built on each item (all with the same template) to only show items in a folder that have a field value equal to that of the current item's ID. In case you're already lost, here's an example of the structure:
- sitecore
- content
- Home
- ContentItem1 (with droplist)
- Site Data
- SelectableItem1(ContentItem1 selected in 'itemid' field)
- SelectableItem2(ContentItem1 selected in 'itemid' field)
- SelectableItem3(ContentItem1 not selected in 'itemid' field)
- SelectableItem4(ContentItem1 not selected in 'itemid' field)
- templates
- ContentItem1Template
- Droplist field (source set to below query)
I want my query to assign the ContentItem1's droplist field source dynamically by getting a list of items that have ContentItem1's id as their 'itemid' field's value, but by comparing the field value to that of the ContentItem1 id. I have tried doing this by comparing the field's value to the id token, like so:
query:/sitecore/content/Site Data/*[##itemid#=$id]
No matter what value I try for id ('$id', $id, #id, '#id', ##id, '##id', etc.) it does not want to resolve on the item level. Is there some way to do this so that I can reuse this ContentItem1Template for all of my items that need the same functionality?
If you are using Sitecore 7 then you can use coded field datasources. This will allow you to use any custom logic you like to specify the items which should appear in your lists.
Create a class that implements IDataSource and the ListQuery() method that returns a list of Items as the source of your field. Then set the source of your field to your method with the code: prefix, e.g. code:MyProject.Custom.FieldDataSource,MyProject.Custom
using System;
using Sitecore.Buckets.FieldTypes;
using Sitecore.Data.Items;
namespace MyProject.Custom
{
public class FieldDataSource : IDataSource
{
public Item[] ListQuery(Item item)
{
var root = item.Database.GetItem("/sitecore/content/my-item");
// some other logic to filter your item set
return root.Children.ToArray();
}
}
}
These articles should help you:
Custom Classes as Data Template Field Sources
Having code as your field its datasource
You may need to wrap the ID in single quotes like so:
query:/sitecore/content/#Site Data#/*[#itemid='$id']
That said, this seems like a good fit for using the Sitecore Link Database. Whenever you associate a SelectableItem to a ContentItem, Sitecore will store that relationship in the Link database (as long as you reference it using a field that supports it, such as a DropLink, DropTree, GeneralLink, etc.).
From there, you can use Globals.LinkDatabase.GetReferrers(contentItem) or contentItem.Links.GetValidLinks() to get a list of all referring items to the content item. This is where you can filter down the list by template ID to ensure that you only return SelectableItems.