Wednesday, April 23, 2014

Unable to see save as site template

If your unable to see save as site template below might be the reason for that.

You save a Team site as a template with or without the SharePoint Server Publishing Infrastructure feature activated at the site collection level.
  • Do not activate the SharePoint Server Publishing feature at the site level otherwise the Save site as template option will not be available.
  • By default the Save site as template option is available even if the SharePoint Server Publishing Infrastructure feature is enabled at a site collection level.

Tuesday, April 15, 2014

Cross Site Lookup

Hi Guys,

Today I am going to tell you how to use the jslink for cross site lookup. Recently we got a requirement in our project to create field which looks up the values from different site collection. For that I created 2 components

  1. JSLink for new and Edit form.
  2. Custom service which return the data in the form of json from the specified site collection, list, field.
Below is the screen shot how the Project (Single Line of text) will be rendered like lookup field















(function () {
    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.Fields = {
        'Project': {
            'NewForm': RenderCrossSiteLookup,
            'EditForm': RenderCrossSiteLookup,
        }
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
var currentval = "";

function RenderCrossSiteLookup(ctx) {
    var formCtx = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);
    currentval = formCtx.fieldValue;
    formCtx.registerGetValueCallback(formCtx.fieldName, function () {
        return $("#ddlSourceItems option:selected").text();
    });
    var validators = new SPClientForms.ClientValidation.ValidatorSet();
    if (formCtx.fieldSchema.Required) {
        validators.RegisterValidator(new SPClientForms.ClientValidation.RequiredValidator());
    }
    if (validators._registeredValidators.length > 0) {
        formCtx.registerClientValidator(formCtx.fieldName, validators);
    }
    formCtx.registerValidationErrorCallback(formCtx.fieldName, function (errorResult) {
        SPFormControl_AppendValidationErrorMessage('ddlSourceItems', errorResult);
    });

    var ddlHtml = "<select id='ddlSourceItems' style='width:160px;'></select>";

    return ddlHtml;
}
function CrossSiteLookupService() {
    $.ajax({
        dataType: "json",
        url: "http://<Your Site collection>/_vti_bin/CrossSiteLookupWCF/CrossSiteLookup.svc/GetItems?ListUrl=Lists/Projects%20List&siteUrl=<Site Url from where the data to be pulled>&LookupField=Title",
        success: success
    });
}

function success(response) {
    $json = $.parseJSON(response.GetItemsResult);
    var opt = "<option value=''></option>";
    $.each($json, function (i, item) {
        if (currentval != "" && item.Title == currentval) {
            opt += "<option selected='selected' value='" + item.ID + "'>" + item.Title + "</option>"
        }
        else {
            opt += "<option value='" + item.ID + "'>" + item.Title + "</option>"
        }
    });
    $("#ddlSourceItems").html(opt);

}

function loadScript(url, callback) {
    var script = document.createElement("script")
    script.type = "text/javascript";
    if (script.readyState) { //IE
        script.onreadystatechange = function () {
            if (script.readyState == "loaded" || script.readyState == "complete") {
                script.onreadystatechange = null;
                callback();
            }
        };
    } else { //Others
        script.onload = function () {
            callback();
        };
    }
    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}


loadScript("http://<Your Site Collection>/SiteAssets/Scripts/jquery.min.js", function () {
        CrossSiteLookupService();
});


Sunday, April 6, 2014

What is a Correlation Token ?

A workflow instance interacts with several SharePoint objects (task lists, and documents or items) during its lifetime. In SharePoint, you can have many workflow instances running at the same time and interacting with several objects at the same time. To be able to identify which workflow instance is interacting with which object, you must use an identifier that links one particular workflow instance to one particular SharePoint object. Each workflow instance must be bound to its own items. Such an identifier is called a Correlation Token. A correlation token links a workflow instance to its documents, items, and tasks. It prevents confusion between different workflow instances. We need have one correlation token for the workflow and one for each task we create during the workflow, so that when a user completes a task we have a unique identifier with which to receive any input from the user into the workflow. Make sure correlation token names are not repeated in different task.