Monday, February 20, 2017

Reference error:GetCtxRgiidFromlid is not defined

Recently i encountered a weird issue in SharePoint 2013, when i click on any document library context menu it shows "Reference error:GetCtxRgiidFromlid is not defined" as shown below



After lot of googling and some hit and trial methods, i figured out that this issue is related to the sequence of SharePoint js files in my custom master page.

I used sp.init.js and sp.runtime.js  and gave the reference as
 <script src="/_layouts/15/sp.init.js"></script>
<script src="/_layouts/15/sp.runtime.js"></script>

I gave theses reference because i need to execute some functions (SharePoint jsom api) and these files were required.

But this lead to the reference error so i modified the custom master page and given the links as

<!--MS:<SharePoint:ScriptLink language="javascript" name="sp.runtime.js" OnDemand="true" runat="server" Localizable="false">-->
        <!--ME:</SharePoint:ScriptLink>-->
        <!--MS:<SharePoint:ScriptLink language="javascript" name="sp.init.js" OnDemand="true" runat="server" Localizable="false">-->

First sp.runtme.js is to be loaded then sp.init.js after doing these changes above error was gone.

Happy Coding !!


Thursday, February 16, 2017

Use CK editor in SharePoint default forms

The SharePoint multi column field has some issues as it does not render properly except in internet explorer.

Here i am going to explain you today how you can use third party text editor to use in SharePoint default forms (newform.aspx/editform.aspx). I used ck editor here.

This editor supports multiple editing options and moreover it renders properly in all the browsers.

First i created a columns named "FullHTMLColumn" multiple line of text and choose plain text from
Specify the type of text to allow option 

This columns will store the html content in multiple line of text form

Now you have to place the ck editor files in document library or you can give live links, here i have placed all the editor files in style library and given the reference.
Don't forget to give the jQuery reference, in my case i have given the reference in master page.

Then open the list's newform.aspx and find the PlaceHolderMain and placed the below script in that

<script src="../../Style Library/ckeditor/ckeditor.js"></script>
<script>
var FullHTMLColumn="";


$(document).ready(function(){
FullHTMLColumn=$("[title='FullHTMLColumn']").attr('id');



CKEDITOR.replace(FullHTMLColumn);

});
 function PreSaveAction() { 

$("[title='FullHTMLColumn']").val("<DIV>"+CKEDITOR.instances[FullHTMLColumn].getData()+"</DIV>");


  return true;
  }

</script>

Now open the newform.aspx from browser you will see all the editor options are present on the above column as shown below.

Now you can perform all the text editing option here and save the data in to list.
Use the same script on editform.aspx to show same editor options on that form also



















Now on allitems.aspx and viewform.aspx place the below script under placeholdermain content placeholder.

This script will render the html content inside the multi line of text column, if you will not place this script html will be rendered as plain text

<script type="text/javascript">
$(document).ready(function(){

function render_html()
{

var theTDs = document.getElementsByTagName("TD");

var i=0;

var TDContent = " ";

while (i < theTDs.length) {

try {

TDContent = theTDs[i].innerText || theTDs[i].textContent;

if ((TDContent.indexOf("<DIV") == 0) && (TDContent.indexOf("</DIV>") >= 0)) {

theTDs[i].innerHTML = TDContent;

}

}

catch(err){}

i=i+1;

}

}

render_html();

});

 </script>

Happy Coding !!!

Thursday, February 2, 2017

Create List Items using rest Api in SharePoint

You can create lists records using the powerful rest API that SharePoint provide.

Here is an example how you can do it



<script src="https://code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
function AddListItem() {
         var category = $("select[id$='ddlcategory'] option:selected").text();
        var feedback = $("[id$='txtfeedback']").val();
        $.ajax
            ({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('Feedback')/Items",
                type: "POST",
                data: JSON.stringify
                ({
                    __metadata:
                    {
                        type: "SP.Data.FeedbackListItem"
                    },
                    Title: category,
                    Feedback: feedback
                   
                }),
                headers:
                {
                    "Accept": "application/json;odata=verbose",
                    "Content-Type": "application/json;odata=verbose",
                    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                    "X-HTTP-Method": "POST"
                },
                success: function (data, status, xhr) {

                },
                error: function (xhr, status, error) {

                }
            });
    
    }
</script>
I created this function to create list records in my Feedback list.
I am getting a string value from a text box and from one select box and passing these value to list fields and called this function on button click.

You have to take care of the below code

  data: JSON.stringify
                ({
                    __metadata:
                    {
                        type: "SP.Data.FeedbackListItem"    // This is the list title and the syntax to create item
                    },
                    Title: category,  //These are internal names of fields to which you will be passing values
                    Feedback: feedback
                   
                }),

Happy Coding !!!