1

Is this possible with a calculated column? I have a hyperlinked field in a list, that when clicked, opens an email. Once this field is clicked, I need the choice field (Yes/No) automatically change to No. Possible with calculated column? Workflow? Thanks so much

1

Steps to change choice column on click of hyperlink column

  1. Create a hyperlink column. I have created ‘EmailColumn’

  2. Create a choice column. I have created ChoiceYN. Default value is set to yes.

  3. Copy the code below and paste in text file and save it as Test.js inside Layouts folder. Replace the list name, list id and column names (internal column names) with yours in the code.

    var listName ="TestCL";
    var listId = "{935F312E-1ECA-4D7A-B7ED-EB0C1995B3F9}";
    var hyperLinkColName = "EmailColumn";
    var choiceColNameToChange = "ChoiceYN";
    var listItem;
    var hyperlinkInnerHtml;
    
    var options = {
        OnPostRender: function (ctx)  
        { 
        changeChoiceColOnClick(hyperLinkColName,choiceColNameToChange);
        }
    };
    
    changeChoiceColOnClick = function(hypLnkColumnInternalName ,choiceColInternalName){
    
        for (var i = 0; i < ctx.ListData.Row.length; i++) {
            listItem = ctx.ListData.Row[i];
            var iid = GenerateIIDForListItem(ctx, listItem);
            var row = document.getElementById(iid);
            if(row){
                var hypLnkColumnValue = listItem[hypLnkColumnInternalName];
                    if(hypLnkColumnValue.length > 0)
                    {
                        var listItemId = listItem.ID;
                        $("a[href='" + hypLnkColumnValue + "']").attr("onClick","ResetChoiceToNo('" + listItemId + "','" + choiceColInternalName + "')");
                    }
                }
    
        }
    }
    function ResetChoiceToNo(listItemId , choiceColInternalNameToReset)
    {
     var siteUrl = _spPageContextInfo.webAbsoluteUrl;
        var clientContext = new SP.ClientContext(siteUrl);
        var oList = clientContext.get_web().get_lists().getByTitle(listName);
    
        this.oListItem = oList.getItemById(listItemId);
    
        oListItem.set_item(choiceColInternalNameToReset, 0);
    
        oListItem.update();
    
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }
    
    function onQuerySucceeded() {
    
        alert('Item updated!.Please refresh the page or reload the page in code');
    }
    
    function onQueryFailed(sender, args) {
    
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
    
    
    // Create a function for customizing the Field Rendering of our fields 
    CustomizeFieldRendering = function () {  
        console.log("in CustomizeFieldRendering");
        // Register the rendering template
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(options); 
    }; 
    
    ExecuteOrDelayUntilScriptLoaded(CustomizeFieldRendering, 'clienttemplates.js');
    
  4. Edit the page having the list and add JS link under Miscellaneous to the file you saved in point 2 in layouts folder. /_layouts/15/Test.js

enter image description here

  1. See the image of the list.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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