SharePoint Rest API function needs to work upon page on load

The following does not trigger the function on page load on display mode page.

$(document).ready(function () {
retrieveItems();
});

function retrieveItems(){ …}

You need to use executeOrDelayUntilScriptLoaded(func, depScriptFileName); (https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ff411788(v=office.14)?redirectedfrom=MSDN)

This will  execute any pending jobs waiting for the file to be loaded.

$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(retrieveItems, “sp.js”);
});

 

Posted in SharePoint 2013, SharePoint 2016 | Leave a comment

SharePoint list view issue

Why you cannot open a list when the list exists under the site content…

How to resolve the issue…

  1. Try to create a new view with “All Items”. If it works, you can make this as a default page ( …/allitems.aspx). Solved!
  2. If you get an error (e.g. it already exists), then this page (OOTB default view page)  has an issue.
  3. On the list view,  check if you can see “Default” but not “All Items”. Check if you can  open the page with   …./allitems.aspx, but it is not on the views on the list settings page. Then this views must have been hidden.  Then update SPView using the following PowerShell Script.

$web = Get-SPWeb  $siteUrl
$list = $web.Lists[$listname]
$viewID = $null
foreach($sview in $list.Views){
if($sview.hidden -eq $True){
$viewID = $sview.Id
}
}
$hview = $l.Views |?{$_.Id -eq $viewID}
$hview.title = “All Items”
$hview.Hidden = $False
$hview.Update()
$web.Dispose()

Posted in SharePoint 2013 | Leave a comment

Auditing workflow using Workflow History

When Workflow History list items exceed the list view threshold and cannot see the list views properly, we can get Workflow History data with PowerShell. The following codes will create an excel file including primary item, its worklfow data ( started and completed dates)

$web = Get-SPWeb $SiteUrl
$list = $web.Lists[$listName]

#views
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$camlQuery='<FieldRef Name=”List”/>list guid’
$spQuery.Query=$camlQuery
$items = $list.GetItems($spQuery)

#fields
$bugID = $null
$eventType = $null
$created = $null
$outcome = $null

#file
$outPath = “file path”
$exportlist = $null
$exportlist = @()

foreach($item in $list.Items){
if(($item[“Event Type”] -eq 1) -or ($item[“Event Type”] -le 2)){
$bugID = $item[“Primary Item ID”]
if($item[“Event Type”] -eq 1){
$eventType = “Started”
}
if($item[“Event Type”] -eq 2)
{ $eventType = “Completed”
$created =$item[“Date Occurred”]
$outcome = $item[“Outcome”]
$hash = @{
BugID= $bugID
EventType = $eventType
Date_Occurred= $created
Outcome=$outcome
}
$obj = New-Object PSObject -Property $hash | select  BugId,EventType,Date_Occurred,Outcome
$exportlist += $obj
}
}
}
$exportlist | Export-Csv -path $outPath
$web.Dispose()

Posted in PS | Leave a comment

Explorer View in document library

SharePoint explorer view displays the folder structure on the SharePoint server computer while a user can access it in his/her computer. Two main protocols are  being  used for this feature – “Web Distributed and Versioning(WebDAV)” and “FrontPage Server Extensions Remote Procdure Call(FPRPC)”. When the machine has web client service installed/enabled, WebDAV will be used(\\servername…). If not, FPRPC will be used ( http://servername&#8230;)

http://blogs.technet.com/b/manjesh/archive/2010/01/03/all-about-explorer-view-in-sharepoint.aspx

 

 

 

 

Posted in SharePoint 2010 | Leave a comment

Get a user permission from a site collection

function FindUserPermission( $siteurl, $userLogin, $filepath){
$Site = Get-SPSite -Identity $siteurl

$ExportItem = @()
foreach($web in $Site.allwebs)
{

$rolecollection = $web.RoleAssignments

foreach($roleassign in $rolecollection)
{

[Microsoft.SharePoint.SPPrincipal] $principal = $roleassign.Member

try{

$user =[Microsoft.SharePoint.SPUser] $principal
if($user.UserLogin -eq $userLogin){
$temprole = $null
foreach($role in $user.Roles){
$temprole += $role
}
$ExportUser = New-Object PSObject
$ExportUser| Add-Member -MemberType NoteProperty -name “Url” -value $web.url
$ExportUser| Add-Member -MemberType NoteProperty -name “Name” -value $user.Name
$ExportUser| Add-Member -MemberType NoteProperty -name “Roles” -value $temprole
$ExportItem += $ExportUser
}

}
catch
{

}

try{
$group =[Microsoft.SharePoint.SPGroup] $principal

if($group.Users.Count -gt 0)
{
foreach($user in $group.Users)
{
if($user.UserLogin -eq $userLogin){

$tempgrouprole = $null
foreach($role in $group.Roles){
$tempgrouprole += $role
}
$ExportGroup = New-Object PSObject
$ExportGroup| Add-Member -MemberType NoteProperty -name “Url” -value $web.url
$ExportGroup| Add-Member -MemberType NoteProperty -name “Name” -value $group.Name
$ExportGroup| Add-Member -MemberType NoteProperty -name “Roles” -value $tempgrouprole
$ExportItem += $ExportGroup
}
}
}

}
catch
{

}

}
$web.Dispose()

}#foreach

$ExportItem |Export-CSV $filepath -NoTypeInformation

}

Posted in PS | Leave a comment

Update a SPFieldChoice with PS

Choice field

$webUrl = Get-SPWeb “http://xxx

$listname = “xx”
$web = Get-SPWeb $webUrl
$list = $web.Lists[$listname]
$choicefield = $list.Fields[“SDLC Method”]
$choicefield.choices.add(“xxx”)

$choicefield.update()

$choicefield.choices.remove(“xxx”)

$choicefield.update()

$options = @{“aa”, “bb”…}

$choicefield.choices .clear()

$choicefield.update()

$choicefield.choices.addrange($options)

$choicefield.update()

 

 

Posted in PS | Leave a comment

Get List/Get All Fields

$web = Get-SPWeb  -identity http://sss/sites/ss

$list = $web.Lists(“http://sss/sites/ss/Lists/xx“)

$list.Fields | Sort-Object -Property Title | Format-Table -Property Title

Posted in PS | Leave a comment

When you need to add new documents with explorer in SharePoint library

When you upload a bulk of documents with ‘open with Explorer’ in Document library, you need to verify  the library settings if documents are not required to be checked out. If ‘Require Checkout” is YES and you start putting documents in the library folders with explorer, all documents will be checked out to you and end up in “Manage files which have no checked in version”. Nobody except you  can see the documents. Indeed you need to check in all documents.

For forceful check in, you can use object model programming or PowerShell script.

The following article shows good PowerShell example for this.

http://brenthafnersblog.wordpress.com/2012/10/16/manage-files-which-have-no-checked-in-version-list-larger-than-list-view-threshold/

Posted in SharePoint 2010 | Leave a comment

Open a document in browser

SharePoint can be configured that users can single-click to open a document in the browser:
1. Browser File Handling setting in Central Admin-The default setting is strict and will force the browser to download certain types of files in order to improve the security for the server. E.g. SharePoint treats PDF as a dangerous file. You can set this to be permissive.

2. A browser-enabled application is required.

    a. For this, we must install Microsoft Office Web Applications and configure it to use on our site collection.
    b. Microsoft Web Applications include Word Web Application, Excel Web Application, PowerPoint Web Application, and OneNote Web Application.
    c. If Excel Services is enabled as a feature, excel file can be viewed in browser by Excel Web Access Web part.
    d. Once the office web applications are installed and those service applications are added to the correct web application, the following file formats will be supported in browser view.
    Word .docx, .docm, .doc
    Excel .xlsx, .xlsb, .xls (view-only)
    PowerPoint .pptx, .pptm, .ppt
    OneNote .one

3. Site collection feature setting –“Open Documents in Client Applications by Default” needs to be deactivated for enable-browser opening

4. Document library advanced settings – “Opening Documents in the Browser”

Posted in SharePoint 2010 | Leave a comment

Life, in the end…

Without youth, health, motivation, and love, what life is like…

Posted in Life | Leave a comment