Pages

Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Thursday, March 21, 2013

Get and set BDC Column Value via Javascript

Hi All

We already know very well reagarding "getTagFromIdentifierAndTitle" function in SharePoint which is very useful to set and get the value of TextBox, DataField, Dropdown and many more to set and get the values from control. But what about if your list contains BDC Column value. How to set  and get the value from BDC Column?

Here is the jascript to achieve set and get the BDC column Value.

<script type='text/javascript'>
//set default value
_spBodyOnLoadFunctionNames.push("loadandhideBDC");
function loadandhideBDC()
{
setDefault();
}

//To check it contains value before saving
 function PreSaveAction() {
var elem = getBDCTagFromIdentifierAndTitle("TEXTAREA","Object Picker", 1);
if(elem.value =="")
{
 alert( "Invalid Value");
 return false;
}
}

function getBDCTagFromIdentifierAndTitle(tagName, title, count) {
var tags = document.getElementsByTagName(tagName);
var myCount = 0;
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title){
myCount++;
if(count == myCount){
return tags[i];
}
}
}
return null;
}


function setDefault() {
var variety = "";
var elem = getBDCTagFromIdentifierAndTitle("TEXTAREA","Object Picker", 1);
if(elem) elem.value = variety;
var elem = getBDCTagFromIdentifierAndTitle("DIV","Object Picker", 1);
if(elem) elem.innerText = variety;
}
</script>

Disha Shah

Tuesday, August 9, 2011

SharePoint 2010: Change the “Add New Item” (and other) messages for a all SharePoint List Types

In SharePoint, to add a new item/document we always have one standard message like “Add a new item”.

Users who are familiar with SharePoint they are used to understand but sometimes users do not understand they have question why I it always has said “ Add a new item”. So to avoid confusion let us add user friendly message.

How to do that? Let us use power of javascript.

Steps:

1. Add a content editor webpart in the page and add this javascript. Add Content Editor Webpart at the end of the page after list.

2. “<script> document.getElementById("idHomePageNewItem").innerHTML="Click here to insert a new country"</script>”
This is just the text message for SharePoint Custom List how to make change for each type of list.

Below is list for id for every SharePoint list type.

ID’s used by web parts
SharePoint List Type
Default message
ID for “.getElementById” in the code below
Announcements
Add new announcement
“idHomePageNewAnnouncement” (changed in 2010)
Links
Add new link
"idHomePageNewLink" 
Calendar
Add new event
"idHomePageNewEvent"
Picture Library
Add new picture
“idHomePageNewItem”  *  (changed in 2010)
KPI List
Add new item
"idHomePageNewItem"  *  (changed in 2010)
Tasks
Add new item
"idHomePageNewItem"  *  (changed in 2010)
Project Tasks
Add new item
"idHomePageNewItem"  *  (changed in 2010)
Document Library
Add new document
"idHomePageNewDocument" 
Wiki
Add new Wiki page
"idHomePageNewWikiPage"  
Discussion
Add new discussion
"idHomePageNewDiscussion" 
Custom List
Add new item
“idHomePageNewItem”

Hope this helps!!!
Disha Shah

Tuesday, November 2, 2010

How to Hide ItemToolbar in SharePoint 2007?

Hello


We have business requirement which indicates that User should not see entire toolbar when they view any item, how to disable that?
Simple Approach with JavaScript inside the ContentEditor Webpart

<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("hideFields");
function hideFields() {
   var control = document.getElementById('controlID');
    control.style.display="none";
}
</script>

NOTE: you can find the control ID by downloading Internet Development toolbar and just select that element it will show that control ID.

Disha Shah