Glass Mapper RenderLink language embedding - sitecore

In Sitecore 8, we are currently generating menu items using Glass Mapper's #RenderLink method. We have set the "languageEmbedding" attribute of the LinkManager Provider to "never" but glass seems to ignore this setting.
$RenderLink(mi, x => x.Link_URL);
creates
http://domain.com/en/topics/xxxx
Looks like you can do this on a per item basis (http://blog.falafel.com/sitecore-removing-languages-from-urls/) by doing the following:
Sitecore.Links.LinkManager.GetItemUrl(item,
new Sitecore.Links.UrlOptions
{
AlwaysIncludeServerUrl = true,
LowercaseUrls = true,
LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Never
});
but I haven't been able to figure out how to get this into glass.
Does anyone know how to remove the "/en/" (language) from the link when using glass to render?

You can set this on the SitecoreField attribute of your model
[SitecoreField(UrlOptions = SitecoreInfoUrlOptions.LanguageEmbeddingNever|SitecoreInfoUrlOptions.AlwaysIncludeServerUrl)]
public virtual Link Link { get; set; }

Double check something else is not overriding this setting. I would do a /sitecore/admin/showconfig.aspx just to make sure there isn't another linkprovider which has patched the web.config.

Agree with the others. Check your showconfig. Failing that, do a search of all the config files. In my specific case, I found that Sitecore.Ecommerce.config was patching the linkmanager and wasn't showing in showConfig that it was doing so. After updating that config, the link manager functioned normally.
Note: Sitecore 8.0-u3, Active Commerce 3.2, SES 2.2

Related

Enabling Change Tracking for Entity

Is there a way to enable change tracking for couple of entities programmatically? I could not find any api in Dataverse which can help to do this.
You cannot do that with webapi but you can definitely achieve this programatically.
you can either create console application or you can run code now plugin for xrmtoolbox and get this done.
Below code snippet for reference.
UpdateEntityRequest updateBankAccountRequest = new UpdateEntityRequest
{
Entity = BankAccountEntity,
ChangeTrackingEnabled = true //or false here
};
_serviceProxy.Execute(updateBankAccountRequest);
Microsoft docs for ChangeTrackingEnabled

Microsoft Dynamics CRM - Pass Parameters from Web Service to IPlugins

We are building some plugins in Microsoft Dynamics CRM by inheriting from IPlugin. We have these configured so they fire whenever an Account is updated.
The problem is the plugins are calling our services, which causes our service to respond with an update. We are doing some pretty hacky things right now to prevent these cyclical updates from happening.
We were wondering if there was a way to pass a value to the IOrganizationService service (the web service) that a plugin can look at. Our other system could send a flag ("hey, don't bothing sending an update!") and the plugin could skip calling back.
Can we pass parameters from web service to the plugins?
Good idea could be usage of custom flag-field. For example you add bit field and call it CallFromExternalSystem. So when you make an update from your external system through IOranizationService you just fill this flag with true field and in plugin you can check condition that this field is present in fields list so you have no need to call external system endpoint again.
We decided the correct solution was to use the value found in IPluginExecutionContext.InputParameters["Target"]. In the case of an Update, this returns an Entity containing attributes for all the attributes that were updated.
We basically have a list of attribute names we cared about. We loop through names and see if any of them appear in the entity attribute list. If so, we send an update to our other system. The good news is, Dynamics CRM ignores updates where the values don't actually change, so trying to update a value to itself is no-op.
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity entity = (Entity)context.InputParameters["Target"];
string[] fields = new string[] { "name", "statecode", "address1_line1" };
bool hasUpdates = fields.Where(f => entity.Attributes.Contains(f)).Any();
if (!hasUpdates)
{
return;
}
}

How to prevent Sitecore modal dialog from redirecting user to new item?

I’m stuck with a little development annoyance. I have crated an application to extend Sitecore authoring interface.
The application queries some internal services and asks few additional questions from a content author before creating an new content item in Sitecore.
I have modeled the app on (Sitecore.Shell.Applications.Templates.CreateTemplate.CreateTemplateForm).
The problem I’m having is, as soon as an item is created my WizardForm is reloaded to load newly created item.
What I want is for the wizard to go through to the “Final” page and reload the main UI once the modal dialog is closed.
Exactly how new OOTB template wizard works. I know that if I comment my item creation code out the UI behaves as expected.
Looks like a create of an item generates some events in the background that UI is responding to and reloads my modal dialog with the newly created item. (I have tried the following solutions http://sdn.sitecore.net/Forum/ShowPost.aspx?postid=29092, http://sdn.sitecore.net/Forum/ShowPost.aspx?postid=29968, however this does not seem to solve it for me).
The original code seems to disable events like so:
this.CreateTemplatePicker.DisableEvents();
TemplateItem templateItem = Client.ContentDatabase.Templates.CreateTemplate(this.TemplateName.Value, selectionItem);
this.CreateTemplatePicker.EnableEvents();
I have tried the following:
Client.Site.Notifications.Disabled = true;
var item = container.Add(ItemUtil.ProposeValidItemName(this.Title.Value), Settings.ProductImageTemplateID);
Client.Site.Notifications.Disabled = false;
AND OLSO
Item item;
using (new EventDisabler())
{
item = container.Add(ItemUtil.ProposeValidItemName(this.Title.Value), Settings.ProductImageTemplateID);
}
All with the same result. The wizard modal dialog is reloaded as soon as I get to the page where the item is created.
Using fiddler I can see the command to reload the windows is sent to the client. I just cant figure out how do I tell Sitecore UI to ignore the event(s) or alternatively prevent event(s) from being generated in the first place. The first command being sent to the UI below tells the page to load Content Editor, exactly the thing I'm trying to prevent.
{"commands":[
{"command":"SetLocation","value":"/sitecore/shell/sitecore/content/Applications/Content%20Editor.aspx?fo=%7b186F686E-A8FF-4303-B59F-4D284A5A0196%7d&db=master&id=%7B186F686E-A8FF-4303-B59F-4D284A5A0196%7D&la=en&vs=1"},
{"command":"SetDialogValue","value":"{186F686E-A8FF-4303-B59F-4D284A5A0196}"},
{"command":"SetStyle","value":"none","id":"Constraints","name":"display"},
{"command":"SetStyle","value":"","id":"LastPage","name":"display"},
{"command":"SetAttribute","value":true,"id":"NextButton","name":"disabled"},
{"command":"SetOuterHtml","value":"<button id=\"CancelButton\" class=\"scButton\" TabIndex=\"0\" onclick=\"javascript:return scForm.postEvent(this,event)\" onkeydown=\"javascript:scForm.handleKey(this, event, null, '32')\">Finish</button>","id":"CancelButton"},
{"command":"Focus","value":"CancelButton","scrollintoview":"0"},{"command":"Eval","value":"scUpdateWizardControls();"},
{"command":"SetAttribute","value":true,"id":"BackButton","name":"disabled"},{"command":"Eval","value":"scAlignWizardButtons()"}
]}
Just a little info about my Sitecore environment:
Sitecore started
Sitecore.NET 7.0. (rev. 130810)
C:\Inetpub\wwwroot\sc71\Website\bin\Sitecore.Client.dll (Sitecore CMS, Sitecore Client Application, 7.0 rev. 130810)
C:\Inetpub\wwwroot\sc71\Website\bin\Sitecore.Kernel.dll (Sitecore CMS, Sitecore CMS Kernel Library, 7.0 rev. 130810)
C:\Inetpub\wwwroot\sc71\Website\bin\Sitecore.Nexus.dll (Sitecore.Nexus)
Operating system Microsoft Windows NT 6.2.9200.0
Microsoft.NET version 4.0.30319.18051
Process id: 8040
Windows identity used by the process: NT AUTHORITY\NETWORK SERVICE. Impersonation: False
Managed pipeline mode: Integrated
In the end the problem only affected bucketable items. No need to disable event or anything, that was a red herring. However, in my case I am working with buckets and bucketable items, so I needed to get it fixed.
The offending code ended being Sitecore.Buckets.Commands.AddFromTemplateCommand(). Thanks to Sitecore support engineers for getting to the bottom of this. A proposed workaround, that worked for me is as follow. This have been reported to Sitecore development team and I guess will be resolved at some stage in a future release of Sitecore. The current (at the time of writing) version Sitecore.NET 7.0. (rev. 130810) is affected.
You will need to substitute existing implementation with your own (see code below). To replace existing implementation overwrite the following configuration /App_Config/Includes/Sitecore.Buckets.config file at /sitecore/databases/database[#id="master"]. I ended up creating a configuration patch file that looked like this.
Configuration:
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<databases>
<database id="master" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
<Engines.DataEngine.Commands.AddFromTemplatePrototype>
<obj patch:instead="obj[#type='Sitecore.Buckets.Commands.AddFromTemplateCommand, Sitecore.Buckets']"
type="Sitecore.Support.Buckets.Commands.AddFromTemplateCommand, MyAssembly"/>
</Engines.DataEngine.Commands.AddFromTemplatePrototype>
</database>
</databases>
</sitecore>
</configuration>
Code:
using Sitecore.Data.Items;
using Sitecore.Text;
using Sitecore.Web.UI.Sheer;
using System;
using System.Web;
namespace Sitecore.Support.Buckets.Commands
{
public class AddFromTemplateCommand : Sitecore.Buckets.Commands.AddFromTemplateCommand
{
protected override Sitecore.Data.Engines.DataCommands.AddFromTemplateCommand CreateInstance()
{
return new AddFromTemplateCommand();
}
protected override void SetLocation(Data.Items.Item item)
{
if ((HttpContext.Current != null) && (Context.ClientPage != null))
{
// This condition is set to go around an issue when a bucket item is created from within a custom wizard app.
// Replace the specified path with your own one.
if (Sitecore.Context.RawUrl != null && !Sitecore.Context.RawUrl.Contains("/sitecore/shell/Applications/Issues/Create Product Bucket.aspx"))
{
UrlString str = new UrlString(Sitecore.Buckets.Util.Constants.ContentEditorRawUrlAddress);
str.Add(Sitecore.Buckets.Util.Constants.OpenItemEditorQueryStringKeyName, item.ID.ToString());
item.Uri.AddToUrlString(str);
UIUtil.AddContentDatabaseParameter(str);
SheerResponse.SetLocation(str.ToString());
}
}
}
}
}

How do I use the preview date in preview mode to show date-specific content in Sitecore?

In the site I'm working on, certain content only appears once a certain date is reached:
public bool IsActive
{
get { return System.DateTime.Now >= this.IssueDate.DateTime; }
}
I want to test this code using the preview mode functionality and the experience bar. However, System.DateTime.Now always returns the real current date, regardless of preview mode. How do I write this so I can guarantee that the date set in the experience bar is respected, but while in normal mode the page still uses System.DateTime.Now?
Sitecore version: 6.4.1 rev. 110720
Update: I can't use publishing restrictions because children of this item need to be published and visible before this item appears in the menu that is controlled by this logic.
Sitecore provides a pair of properties to aid in this situation:
bool Sitecore.Configuration.State.Previewing
DateTime Sitecore.Configuration.State.PreviewDate
The Sitecore.Configuration.State.Previewing property is true if preview mode is on, false otherwise. The Sitecore.Configuration.State.PreviewDate property returns the Sitecore.Sites.SiteContext.DisplayDate, which is set to the date in the experience bar in preview mode.
Here is the code I ended up using:
public bool IsActive
{
get
{
DateTime dateToUse;
if (Sitecore.Configuration.State.Previewing)
{
dateToUse = Sitecore.Configuration.State.PreviewDate;
}
else
{
dateToUse = DateTime.Now;
}
return dateToUse >= this.IssueDate.DateTime;
}
}
It appears to work fine without side effects.
The best approach to handle something like this is instead to restrict content from being published until a certain date.
In the content editor, on the Publish tab, click the Restrictions button to restrict when content can be published.
If you need content to go live at a certain date and time, you can leverage the Automated Publisher module for this.
You should be able to get the selected date by using WebEditUtil.GetCurrentDate().
If you don't wan't to reference that, check the cookie "sc_date".
I don't think using Sitecore.Configuration.State.PreviewDate alone will cause any issues as it always returns the dateTime ( of when the request is made).
EDIT:
In case of AJAx calls to the same page/Code Sitecore.Configuration.State will be null, so make sure you handle it.
An alternative is to update the SystemTime.CurrentTime method. In Global.asax.cs, in Application_BeginRequest, add the following:
SystemTime.CurrentTime = () =>
State.Previewing || State.WebEditing
? State.PreviewDate
: DateTime.Now;
Now anywhere you seek DateTime.Now it will return the proper date.

I get the "FilenotfoundExceptionunhandled" ? in Console application while displaying the SharePoint site list name

Error Details:
The Web application at
http://dev001aaamaaind:333/ could
not be found. Verify that you have
typed the URL correctly. If the URL
should be serving existing content,
the system administrator may need to
add a new request URL mapping to the
intended application.
string urlSite = "http://dev001aaamaaind:333/";
using (SPSite sc = new SPSite(urlSite))//Getting Error in the line
{
SPWeb site = sc.RootWeb;
foreach (SPList list in site.Lists)
{
if (!list.Hidden)
Console.WriteLine(list.Title);
}
}
Make sure that you have set the Platform in the Project Properties Build tab to either to x64 or Any CPU. This is one common issue that hit when developing using SharePoint 2010 as it is based on 64 bit Arch.
http://spserver2010.blogspot.com/2010/09/visual-studio-2010-beta-console.html