Tuesday, August 26, 2014

How to query SP2013 Managed metadata term store with JSOM

This post will show how to read the Taxonomy Term Store with JSOM.
Taxonomy Term store can be accessed in a SharePoint App, with permission scope of Taxonomy.
To be able to use the JSOM API for Taxonomy you need to reference SP.Taxonomy.js found in _layouts/15/ the best way to reference this would be in the document ready.

 $(document).ready(function () {  
 var scripRef = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";  
 $.getScript(scripRef+ "SP.Runtime.js",  
 function () {  
 $.getScript(scripRef+ "SP.js", function () {  
 $.getScript(scripRef+ "SP.Taxonomy.js", function () {  
 context = SP.ClientContext.get_current();  
 //Call your code here.  
 getTermStores();  
 });});});})  

Read from Taxonomy

 function getTermStores() {  
   session = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);  
   termStores = session.get_termStores();  
   context.load(session);  
   context.load(termStores);  
   context.executeQueryAsync(  
 function(){  
 termStoreEnum = termStores.getEnumerator();  
    var termStores = "TermStores: /n";  
    while (termStoreEnum.moveNext()) {  
     var currentTermStore = termStoreEnum.get_current();  
     var termStoreID = currentTermStore.get_id();  
     var termStoreName = currentTermStore.get_name();  
 termStores += "Name: " + termStoreName + " ID:" + termStoreID;  
 }  
 }, function(){  
 //failure loading.  
 });  
 }  

Tuesday, April 8, 2014

SharePoint Designer 2013 Workflow changes

Already, there are so many articles published about the new features and changes in SharePoint Designer 2013 that it’s a little late to write about this. But I think this would be useful.

There are many new functionalities and enhancements added into SharePoint designer 2013.
Added features allow designers to do more with workflows without requiring a developer to write custom code.

If you select SharePoint 2013 option while creating workflow, you will get the following list of new features

1. Stages

With 2013, concept of stage is introduced. It acts as containers in workflow, which allows one to structure the workflow from one stage to the other. Stages can be added to a workflow by clicking on Stage icon.





Key points for Stages:


  • All actions in the workflow must be contained in a stage
  • A stage can hold one or more workflow actions, and will also have only one Transition to stage area. 
  • The Transition to stage area defines how the workflow exits the stage after its actions have been processed. The stage can be configured to transition to another stage, or to end the workflow.
  • Workflows must have at least one stage, and it is not possible to nest stages in a workflow.
2. Actions

In 2013 new workflow actions are also introduced and they can be used while designing workflow.



Adding this action to a workflow allows a designer to create a single task, assign it to a specific user, and save the Outcome and TaskID values to workflow variables.



3. Assign a Task

Click on "Assign a task" action from actions menu, and the container displayed in above image, will show up.
Now click on thisuser, which will open the following dialogue.




4. Start a Task Process:
This action is the same as “Assign a Task” action, with the difference being that multiple participants can be assigned to the task being created. The participants can be assigned to the task one at a time (serial, meaning the first participant must respond to the task before the next participant is assigned, and so on.), or all participants can be assigned to the task at the same time (parallel).

                                    


5. Loops

There are two types of looping available: 


  • Loop n Times: Loop type allows a designer to create a looping condition where the actions contained in the loop container are executed a specified number of times.
  • The Loop with Condition: Loop type allows a designer to create a looping condition where the actions contained in the loop container are executed until a specified condition is met.

Key points for loops:
  1. Loops must be contained within a stage.
  2. A stage can be added inside a loop.
  3. Loops can have only one entry and only one exit point.
  4. Nested loops are also supported.
6. Call HTTP Web Service

This action allows you to call a REST-based web service without writing custom code. You specify the URL to the web service you wish to call, along with the HTTP method (GET, PUT, POST, and DELETE).

7. Visual Designer
In SharePoint Designer 2013 the Visual Designer is also introduced. This designer is only available for workflows on the 2013 platform, and you will need Visio 2013 Professional installed on your PC to have this available in SharePoint Designer.
When creating a workflow, you can switch to the Visual Designer by selecting it from the ribbon:


 
This will switch the view of the workflow you are designing to a view that looks a lot like a diagram in Visio:
With all these new features in the SharePoint designer, it has now become more powerful and strong enough for developer to not want to go for custom coding!


Thursday, February 6, 2014

Workflow gets canceled automatically with (500) Internal Server Error.


Workflow is getting cancel with the HTTP 500 error. 

Problem:

RequestorId: 9dea9a29-bb82-214a-0000-000000000000. Details: RequestorId: 9dea9a29-bb82-214a-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.ApplicationException: HTTP 500 {"Transfer-Encoding":["chunked"],"X-SharePointHealthScore":["0"],"SPClientServiceRequestDuration":["30"],"SPRequestGuid":["9dea9a29-bb82-214a-92f0-943af4411ac2"],"request-id":["9dea9a29-bb82-214a-92f0-943af4411ac2"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"MicrosoftSharePointTeamServices":["15.0.0.4420"],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1; RequireReadOnly"],"Cache-Control":["max-age=0, private"],"Date":["Fri, 31 Jan 2014 20:19:03 GMT"],"Server":["Microsoft-IIS\/7.5"],"X-AspNet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"]} at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor

Probable solution/findings to verify:

1. Generally occurs with send email functionality in workflow.
2. Check outgoing email settings for the farm are correct.
3. Disabled firewall on the Exchange/SMTP server.
4. Check App management service is running, UPA is set up and  completed sync such that the user running the workflow has a profile.

Monday, December 9, 2013

Custom action to a callout in SharePoint 2013


During my POC, I was trying to add custom action to a callout same like, Share and follow.found easy way to do it with following script.

 SP.SOD.executeFunc("callout.js", "Callout", function () {  
  var itemCtx = {};  
  itemCtx.Templates = {};  
  itemCtx.BaseViewID = 'Callout';  
  // Define the list template type  
  itemCtx.ListTemplateType = 101;  
  itemCtx.Templates.Footer = function (itemCtx) {  
    
   return CalloutRenderFooterTemplate(itemCtx, AddCustomAction, true);  
  };  
  SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx);  
 });  
 function AddCustomAction (renderCtx, calloutActionMenu) {     
  // Add custom action  
  calloutActionMenu.addAction (new CalloutAction ({  
   text: "Custom Action",  
   tooltip: 'This is your custom action',  
   onClickCallback: function() { console.log('Alert from custom action'); }  
  }));  
 }  




We are good to go!!

Sunday, December 8, 2013

PowerShell to Cancel All SharePoint Workflows in Progress

I was struck with requirement were having big list and workflow attached to it, need to cancel all running workflows. 
It could be either manually traverse all the way and stop it, was next to impossible.
Following script helped me to save my time!


$web = Get-SPWeb "http://mysharepointserver.com/subsite";
$web.AllowUnsafeUpdates = $true;    

$list = $web.Lists["CustomListName"];
$count = 0

foreach ($listItem in $list.Items) 
{
 foreach ($workflow in $listItem.Workflows) 
 {
 
  if(($listItem.Workflows | where 
  {$_.InternalState -ne "Completed"}) -ne $null)
  {
   #Cancel Workflows        
   [Microsoft.SharePoint.Workflow.SPWorkflowManager]::
     CancelWorkflow($workflow);      
   write-output "Workflow cancelled for : 
     " $listItem.Title;  
  }
 }
}
$web.Dispose();
Hope this will save your time!

Monday, September 30, 2013

SP2013 : Task list not visible to other users

I came across weird issue, I created a task list with the system account.
This list is not able to view by any other users.
Spent enough time on finding a cause. It was all due to IE, it was working fine with Chrome and other browsers.

To make it work with IE:
1.  Active x and JS permissions has to be enabled.
2. The site has to be in the trusted pool of you internet explorer. 
3. Disable any extra add-ons.

Hope this small piece of information will save time

Wednesday, September 11, 2013

Create a custom view on Workflow Task Status

I came across to the requirement to create a custom view based on workflow status.

Requirement was to show all the approved items.


I found a interesting stuff, Filter will not work if we use words like below image:


we would need use the number rather than the words (e.g. 2 instead of In Progress, 4 instead of Cancelled etc)

Following list might help for this kind of requirement:

Status
Value
Not Started
0
Failed on Start
1

In Progress
2

Error Occurred
3

Canceled
4

Completed

5
Failed on Start (retrying)

6
Error Occurred (retrying)
7

Canceled
15

Approved
16

Rejected

17

Hope this will save your time!