Working with Sitecore 9 (update 1) and SXA 1.7.

I am facing an issue related to Context.Item in Sitecore Form Save Action. In the case of Web Database, Sitecore.Context.Item is throwing null in Custom Save Action. Is there any way to get the current item in the custom save action? I am using Sitecore Forms Extension module by Bart Verdonck.

Also, I don't want to uncheck Is Ajax checkbox, it is being used in my form.


2 Answers 2


The issue is that the js file jquery.unobtrusive-ajax.js in the folder \sitecore modules\Web\ExperienceForms\scripts is different from the out of the box Sitecore and Sitecore extensions.

See here. https://github.com/bartverdonck/Sitecore-Forms-Extensions/tree/master/src/Feature/FormsExtensions/code/sitecore%20modules/Web/ExperienceForms/scripts

You need to copy back in the js files from the out of the box Sitecore install.

I just submitted a bug request to the forms extension for this. https://github.com/bartverdonck/Sitecore-Forms-Extensions/issues/50


I don't think this issue is only related to any Sitecore forms extension issue. Context item will be null because SaveAction is evaluated in a Ajax call. I faced with this issue in Sitecore 9.2 and I was able to solve with the following code (item resolving) because Ajax request contains the context page url in the Referer header.

if (!string.IsNullOrEmpty(HttpContext.Current.Request.Headers["Referer"]) 
     && !string.IsNullOrEmpty(HttpContext.Current.Request.Headers["X-Requested-With"]) 
     && HttpContext.Current.Request.Headers["X-Requested-With"].Equals("XMLHttpRequest"))
    var url = new Uri(HttpContext.Current.Request.Headers["Referer"]);
    var homePath = Context.Site.StartPath;

    if (!homePath.EndsWith("/"))
        homePath += "/";

    var itemPath = MainUtil.DecodeName(url.AbsolutePath);
    itemPath = Uri.UnescapeDataString(itemPath);

    if (itemPath.StartsWith(Context.Site.VirtualFolder))
        itemPath = itemPath.Remove(0, Context.Site.VirtualFolder.Length);

    var pageItem = Context.Site.Database.GetItem(homePath + itemPath);

    return pageItem != null ? pageItem.ID.ToString() : string.Empty;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.