Pages

Showing posts with label SharePoint designer. Show all posts
Showing posts with label SharePoint designer. 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

Jquery Redirect After save an item from NewForm.aspx and EditForm.aspx

Hello all

I came across to an situation where user needs to redirect to a "Thank You" or lets say different page when they save item fron "NewForm.aspx" or "EditForm.aspx".

As I do not want to use Visual Studio code that ater save item Event Receiver - "ItemAdded" I tried to look around is there any other option available like Jquery , and yes we can , so easy :)

Here is the code for that.

$(document).ready(function() {

        var button = $("input[id$=SaveItem]"); 
// change redirection behavior 
button.removeAttr("onclick"); 
 button.click(function() { 
             var elementName = $(this).attr("name"); 
             var aspForm = $("form[name=aspnetForm]"); 
             var oldPostbackUrl = aspForm.get(0).action; 
             var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl); 
             var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "custompageurl.aspx"); 
   
             if (!PreSaveItem()) return false; 
             WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true)); 
         }); 
});

Enjoy Jquery!
Disha Shah

Friday, March 30, 2012

Customize the Homepage of SharePoint Blog Sites for Blog Posts Webpart

Hello Friends

The purpose of today Blog is how we can customize view of Posts for Blog Site.
Actually I want to add the new fields on the homepage of the blog site template’s summary view web part for each of the posts.

Let us see how can we do this. Here is step by step process to do this

1. I assume that You have already created your blog site, Add custom column inside the Posts List , in my case it is DelegatedBy which is Person or Group field type.

2. I have downloaded this custom blog.xsl file and upload it to a Site Assets or any other Document Library of your choice. Search for “DelegatedBy” where we added this field to the output which is the only customization that was 
performed on the original XSL.

3. Open the blog site homepage and edit it in SharePoint Designer. Here, you’ll want to click on the Posts web part and add the DelegatedBy column for the field to be displayed in the view.



4. We need to include a link reference to the custom XSL that you had uploaded in Step 2.



5. Save changes that you’ve made in SharePoint Designer and browse to your blog site , magic will happen .

Enjoy Blog Site!!!

Thanks
Disha Shah