Sitecore: multilist during deployment - sitecore

How to enable the multilist to be control in content editor?
for example I have a list of item, item1 to item10. In the standard template value, I defined item1,2,3. After I have deploy the solution, how am I going to enable users in content editor mode or page editor mode to select item7,8,9 and 10?
And also, after I tested/rendered the multilist, only RAW VALUES are being rendered, is there any possible to render the item name such as item1? Do I need to customize the multilist?

The multilist control should be directly visible to the user in the Content Editor, you do not need to do anything else. Since you defined some items in standard values then those will be "pre-selected" when that item is first created. The user can then add the additional items as required.
To allow users to select values from the Page Editor you can Use Sitecore EditFrame in PageEdit
The reason the item is being rendered as the raw value is because you need to get the item and then iterate over the target id's. There is an example of this here here
//Get a multilist field from the current item
Sitecore.Data.Fields.MultilistField multilistField = Sitecore.Context.Item.Fields["myMultilistField"];
if (multilistField != null)
{
//Iterate over all the selected items by using the property TargetIDs
foreach (ID id in multilistField.TargetIDs)
{
Item targetItem = Sitecore.Context.Database.Items[id];
litItemTitle = targetItem.DisplayName;
// Do something with the target items
// ...
}
}
You can use the following instead for the datasource of a repeater
Sitecore.Data.Fields.MultilistField multilistField = Sitecore.Context.Item.Fields["myMultilistField"];
Sitecore.Data.Items.Item[] items = multilistField.GetItems();

Related

Acumatica-LotSerialNbrAttribute screen on mobile app

I'm using Acumatica customization Acumatica-LotSerialNbrAttribute
This customization adds a new screen for look for InventoryID and LotSerialNbr and visualize its attributes.
I'm trying to add this window to the acumatica mobile app.
Here my code:
add screen IN202501 {
add container "InventoryLotSerialContainers" {
add field "InventoryID"
add field "LotSerialNbr"
add group "Attributes" {
displayName = "Attributes"
collapsable = True
add attributes "AttributesAttributes"
}
add recordAction "Save" {
behavior = Save
}
add recordAction "Cancel" {
behavior = Cancel
}
attachments {
}
}
}
And the screen is visible on the mobile app with the 2 selectors
Then I select Inventory and when I select Lot Serial Nbr, the first selector is in blank, causing that I can't review the attributtes neither save the information.
Here the InventoryID selector in blank.
Hope you can help me to successfully publish this screen on acumatica mobile app.
Thanks.
Attributes are a grid style representation in Acumatica. That means you need a container that will show multiple records. I'm getting rusty on mobile pretty quickly, but I believe your definition is set to display a single value value only.
Try adding a separate container for attributes:
add container "AttributesAttributes" {
add field "Attribute"
add field "Value"
}
This should open into a view of multiple records, showing all of your attributes. By specifying the Attribute and Value fields, you should see both data elements in the container.

Regex Validation for TreelistEx is not working

In Sitecore Content editor/Page editor, when I add items to TreelistEx I would like the TreelistEx to allow only 12 items. To achieve this solution, I have added a Regex ^.{0,467}$ in the validation field inside the template section in which I want to limit the items.
I have referred this article
This Regex works properly in Content editor. But for the page editor whenever I add an items in treelistEx it works fine for the first time but again if I add/remove items it gives me validation message for both greater and less number of items just after on click of "Ok"and items are also not saved.
Ideally it should give validation message if number of items are greater than 12 and only on Click of "save" button same as it is working in Content editor. How can I solve this Regex validation problem in Page editor? I am using Sitecore 8.1
I also had the same issue a while ago and because of the limited time i had i implemented a not so ideal way but you can implement it if you want.
Let the user add the items and then just grab the first 12 in your code. It will be something like this:
Create a method to get the multicast item (For flexibility).
public static MultilistField GetMultilistField(Item item, string fieldName)
{
if (item != null && !string.IsNullOrWhiteSpace(fieldName))
{
MultilistField field = item.Fields[fieldName];
if (field != null)
{
return field;
}
}
return null;
}
Get the items within the Miltilist field.
MultilistField field = GetMultilistField[DatasourceItem, "fieldName"];
var returnList = field.GetItems().Where(c => c.TemplateName.Equals("someValidationIfYouWant")).ToList().Take(12);

Disabling/Enabling a oracle apex Tabular Form Attribute based on the value selected in another attribute

I have a tabular form attribute which is a select list with static values Yes/no and another 2 attributes of Date and display.
My requirement is when i select "No" from the Select List, Date attribute should be enabled and Display attribute should be Disabled and If "Yes" From select list Display attribute should be enabled and Date attribute should be Disabled.
Dynamic Action:
Created a Dynamic action:
event = Change
Selection Type = Jquery selector
Jquery selector = `select[name='f06']`
Action = Execute javascript Code
var el = this.triggeringElement.id;
var row = el.split("_")[1];
if ($v(el) == "N") {
// disable the field
$x_disableItem("f04_" + row, true);
}
else {
// enable the field
$x_disableItem("f04_" + row, false);
}
Dynamic action Working perfectly for already created Rows, But not while i am trying to add new Row by selecting Add row.
https://apex.oracle.com/pls/apex/f?p=38210:LOGIN_DESKTOP:115699939041356
App 38210. Apex 4.2.6
Workspace/username/password : nani4850
Kindly help me out experts!!
Adding a blank row involves a partial page refresh, so the Event Scope of your dynamic action needs to be changed from Static to Dynamic in order for the change event handler to remain bound to the triggering elements.
You'll now find you have problems submitting new records, but if you're having difficulty, that's for another question!

sitecore programmatically change imagefield datasource

I need image field source of a product item to change depending on the folder path I am creating a product item under when creating the item in content or page editor.
If I am creating a product under /home/bicycles, I need the product item image field to auto change to /sitecore/media library/Images/bicycles
If I am creating a product under /home/cars, I need the product item image field to auto change to /sitecore/media library/Images/cars
If I am creating a product under /home/scooters, I need the product item image field to auto change to /sitecore/media library/Images/scooters
The default setting for that image field source in the datatemplate is /sitecore/media library/Images/bicycles
How can I go about doing this?
One option is to create a custom Content Editor field that extends the default image field type.
Start by creating a class that inherits from Sitecore.Shell.Applications.ContentEditor.Image. Then override the OnPreRender method to determine and set the Source property of the image field based on your location criteria/requirements.
See comments in the code below for more information.
public class ContextAwareImageField : Sitecore.Shell.Applications.ContentEditor.Image
{
/// <summary>
/// The ItemID proprety is set by the Content Editor via reflection
/// </summary>
public string ItemID { get; set; }
/// <summary>
/// Override the OnPreRender method.
/// The base OnPreRender method assigns a value to the Source viewstate property and we need to overwrite it.
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
Source = GetSource();
}
protected virtual string GetSource()
{
//retrieve and return the computed source value if it has already been set
var contextSource = GetViewStateString("ContextSource");
if (!string.IsNullOrWhiteSpace(contextSource))
return contextSource;
//retrieve the context item (the item containing the image field)
var contextItem = Sitecore.Context.ContentDatabase.GetItem(ItemID);
if (contextItem == null)
return string.Empty;
//determine the source to be used by the media browser
//in this case we're just checking based on parent path, but any logic could be inserted
contextSource = "/sitecore/media library/Images";
switch (contextItem.Parent.Paths.FullPath.ToLowerInvariant())
{
case "/sitecore/content/home/bicycles":
contextSource = "/sitecore/media library/Images/Bicycles";
break;
case "/sitecore/content/home/cars":
contextSource = "/sitecore/media library/Images/Cars";
break;
case "/sitecore/content/home/scooters":
contextSource = "/sitecore/media library/Images/Scooters";
break;
}
//store the computed source value in view bag for later retrieval
SetViewStateString("ContextSource", contextSource);
//return the computed source value
return contextSource;
}
}
Next, perform the following steps:
Login to the Sitecore desktop with administrator rights and use the database icon in the lower right to switch to the Core database.
In the Core database, open the Content Editor then navigate to /sitecore/system/Field Types/Simple Types. There you will find an item representing the Image field type.
Duplicate the Image field type item and rename the duplicated item to something relevant (e.g. Context Aware Image).
Edit the duplicated item
In the Assembly field, provide the name of the assembly file containing your custom image field class (e.g. MyClient.MySite.dll)
In the Class field, provide the name of the custom image field class, including the namespace (e.g. MyClient.MySite.CustomFields.ContextAwareImageField)
Delete the value in the Control field
Save your changes
Switch back to the Master database.
Open the Content Editor, then navigate to a template that should contain your new image field.
Either create a new field in the template and choose your new custom field type in the Type dropdown. Or, change the Type for an existing image field.
Save your template changes.
In the content tree, navigate to an item based on the template above and click the Browse button for the contained image field. The media browser dialog should default to the source location specified by the logic in your custom field.
Note: if you are using a version of Sitecore that contains a SPEAK-based media browser dialog, you will have to switch to Tree View in the dialog (icon in the upper right) in order to see the source location specified by your custom field.

How to render referenced items from current item in Sitecore?

Let say I have item which has its presentation details configured.
In that item I have TreelistEx field keeping reference (GUIDs) to 10+ other items (different templates) somewhere in the tree structure each of them has their own presentation details (sublayouts).
How can I present all reference items on the same page ( as current item) based on their own settings?
I would like to see one page and 10+ pieces of content each with its own layout presentation.
I had a similar problem. Here is the code for rendering sublayouts and xsl renderings:
public IEnumerable<Control> GetRenderingControls(Item item)
{
// Loop through all renderings on the item
foreach (RenderingReference rendering in item.Visualization.GetRenderings(Context.Device, false))
{
// Get the path to the Sublayout
string path = rendering.RenderingItem.InnerItem["Path"];
switch(rendering.RenderingItem.InnerItem.TemplateName.ToLower())
{
case "xsl rendering":
// Create an instance of a XSL
XslFile xslFile = new XslFile();
xslFile.Path = path;
xslFile.DataSource = item.Paths.FullPath;
xslFile.Parameters = GetParameters(xslFile);
yield return xslFile;
break;
case "sublayout":
// Create an instance of a sublayout
Sublayout sublayout = new Sublayout();
sublayout.Path = path;
sublayout.DataSource = item.Paths.FullPath;
sublayout.Parameters = GetParameters(sublayout);
yield return sublayout.GetUserControl();
break;
default:
throw new Exception(string.Format("Unknown rendering template - {0}", rendering.RenderingItem.InnerItem.TemplateName));
}
}
}
Once you get the Controls you can add them to a placeholder and they will be rendered to the page.
Each item with its own layout presentation implies you are getting an entire HTML file... each item will have its own <html>, <head>, and <form> tags. Needless to say, that's going to create a problem.
That being said... This is exactly what Server.Execute() is for. Loop through your TreeList items, use LinkManager to get the URL for the item, and then Server.Execute() to get the rendered output.