Showing posts with label SharePoint Workflow. Show all posts
Showing posts with label SharePoint Workflow. Show all posts

1/11/2018

SharePoint 2013 Workflow Error: Invalid Text Value


I got the not so obvious error below from a simple SharePoint 2013 style workflow.

Invalid text value.
A text field contains invalid data. Please check the value and try again.

The problem was actually pretty simple. I was trying to write more the 255 characters to the Workflow Log. You will get the same error writing more than 255 characters to a Single Line of Text column. You can use an Extract Substring from Start of String action to retrieve only the first 255 characters.


image

4/13/2017

A SharePoint REST API Tester with an AJAX and Workflow Writer

 

A JavaScript project to use with a Content Editor Web Part to test SharePoint REST API calls, and create AJAX sample code and SharePoint Designer 2013 Workflow steps. It includes over 40 ready to test samples to query SharePoint and to create and delete items, folders, lists and sites.

While learning the SharePoint REST API, I created a little REST tester Content Editor Web Part. Later when I explored SharePoint 2013 Workflow REST calls I expanded the tool to include step by step instructions to add the calls to a workflow. After presenting this at the Cincinnati SharePoint User Group and at the Nashville SharePoint Saturday I decided to take the time to clean it up a bit and share it here.

What you will need:

You can also download the file from the GitHub project.



This is the main screen.

image

This is partial list of the sample REST calls. A more complete list is at the end of this article, and I’ll be adding more over time.

imageimageimage

 

The in the page test of a REST call.

image

 

The generated AJAX Code Sample

image

 

The SharePoint 2013 Workflow Steps for the Web Service Call

image

 

Steps to install to your SharePoint Site
  1. If your master page is not already loading jQuery, download jQuery (just about any version) and upload to the Site Pages library. 
  2. Download the SharePointRESTtester.html file to your PC. 
  3. Edit the file and update the line that loads jQuery to point your jQuery file or CDN.
  4. If your master page already loads jQuery, then delete the <script> block that loads the jQuery file.(the first line of the file)
  5. Upload the SharePointRESTtester.html file to your Site Pages library. (Copy the URL to the file.)
  6. Add a Web Part Page to your project:
    1. In the Site Pages library, click the FILES ribbon, click New Document and click Web Part Page.
    2. Enter a page name like "SharePointRESTtester". 
    3. From the library dropdown select Site Pages
    4. Click Create.
  7. Click Add a Web Part
  8. Add a Content Editor Web Part.
  9. Click the web part's dropdown and click Edit Web Part.
  10. Enter or paste the path to the SharePointRESTtester.html file.
  11. Click OK and then in the ribbon click Stop Editing.
  12. You should now see the tester. Click the dropdown and you should see data in the boxes. If not, then the jQuery library did not get loaded.
  13. Add to your Quick Launch or your Follow list!

 

To use the tester…
  1. Select a sample from the dropdown, or enter your own URL, Method, Header JSON and if needed, the Body JSON.
  2. Find the Do It! button. The first check box will actually run the code. *** Warning Will Robinson, stuff could get added, changed or deleted! ***
  3. The second and third checkboxes simple hide or show the JavaScript Ajax code and the SharePoint 2013 workflow steps.

 

SharePoint REST Examples for Queries

  • Get information about the current site collection.
  • Get information about the current web.
  • Get the Regional Settings for the current web.
  • Get the Time Zone for the current web.
  • Get SharePoint's list of Time Zones.
  • Get a list of all webs below the current web.
  • Get the primary site collection administrator (Owner).
  • Get the primary site collection Secondary Contact.
  • Get a web's LastItemModifiedDate
  • Get a list of lists from the current web. (all data)
  • Get a list of lists from the current web. (Just the title)
  • Get a count of items in a library.
  • Get a count of items in a library. (Option #2)
  • Get all items in a list/library.
  • Get all items in a library with filename and path.
  • Get a list folder's properties.
  • Get a count of items in a list folder.
  • Get all items in a list/library filtered by date.
  • Get all items in web level recycle bin.
  • Get selected properties of all items in web level recycle bin.
  • Get all items in a list/library filtered by a range of dates.
  • Search
  • People Search

SharePoint REST Examples for Lists

  • Create a new list
  • Add a new item to a list
  • Add a new folder to a list
  • Delete an item from a list using ID
  • Delete an item, to the Recycle Bin, from a list using ID
  • Update an item using ID
  • Delete a list
  • Delete a list to the Recycle Bin

SharePoint REST Examples for Sites

  • Create a new subsite.
  • Delete a site (Warning Will Robinson! Does not go to the Recycle Bin!)

SharePoint REST Examples for User Profiles

  • Get User Profile info about the current user.
  • Get all User Profile properties for a user.
  • Get User Profile info about a user's manager.

SharePoint REST Examples for Permissions

  • Get a list of Role Definitions for a site.
  • Get a list of Site Users. The ID is useful when setting permissions.
  • Get a list of Site Groups. The ID is useful when setting permissions.
  • Get a list of Site Groups by name.
  • Get a list of Site Groups where name contains 'string'.
  • Break inheritance on a subsite.
  • Break inheritance on a list.
  • Break inheritance on a list item.
  • Grant permissions (Role Assignment) on a list.
  • Remove permissions (Role Assignment) on a list.

SharePoint REST Examples for Filter Select and OrderBy

  • Get a list of Site Users who are not Site Collection admins. Get selected fields and sort.

SharePoint REST Examples for SharePoint 2010 style REST - _vti_bin/ListData.svc

  • Get a list of lists and libraries (EntitySets).
  • Find list items greater than a date.
  • Find list items between two dates.

 

.

8/11/2016

Using Relative URLs in SharePoint 2013 Workflow Calls

 

(For SharePoint 2013, 2016 and SharePoint Online.)

It's generally a good idea to use relative URLs when creating something that you will want to use in more than one place. While not real obvious, you can easily do this in SharePoint 2013 workflow web service calls.

Absolute URL:
   http://yourServerName/sites/yourSiteName/_api/web

Relative URL:
   /sites/yourSiteName/_api/web

What we would like to have in a workflow web service call:
   _api/web

Steps:

  1. After adding your Call HTTP Web Service action, click “this”
    image.
  2. Click the "" button to open the String Builder dialog.
     image
    1. Click the Add or Change Lookup button.
    2. For Data source select Workflow Context.
    3. For Field from source select Current Site URL.
    4. Immediately after the lookup place holder (i.e. no spaces) type the rest of the URL for the web service call:
         _api/web

      image
    5. Click OK.
  3. Continue with web service call action configuration…

 

As you can probably guess… I’m working on a new class that includes workflows!

.

10/25/2015

SharePoint: Launch a Site Workflow from a Link or Button

The following has been tested with SharePoint 2010 and 2013…

There are a lot of questions in the various forums on how to start a Site Workflow, mostly because it is a bit hard to find in SharePoint. For those looking for only that, here's the basic steps:

Start a Site Workflow

  1. Click Site Actions (2010) or Settings (gear) (2013).
  2. Click View All Site Content (2010) or Site Contents (2013).
  3. Click Site Workflows.
  4. Click the workflow!
  5. If displayed, complete the workflow initiation form. (2010 workflows always display an Initiation Form, even if has only OK and Cancel buttons.)

 

Launching a workflow from a link, button or Quick Launch

Instead of telling your users to go find the Site Workflows page it might be better just to give them a link or button to click. All we need is to know how (and where) to copy and paste the URL or JavaScript and then how to use that to create the link.

image

In SharePoint 2010 there are only two ways to launch a Site Workflow from a link, while in SharePoint 2013 there are four!

For 2010:

SharePoint 2010 Site Workflows have two possible URLs to launch workflows, one for workflows with InfoPath forms and one for workflows with ASPX forms. The kind of form you get depends on your edition of SharePoint. For Foundation, SharePoint Designer creates ASPX forms, while for Standard and Enterprise SharePoint Designer creates InfoPath (.XSN) forms. You can force ASPX forms by disabling the hidden "OffWFCommon" feature. (See note at the end of this article.) 

For Foundation: (ASPX forms)

http://yourServer/sites/yourSite/Workflows/yourWorkflowName/yourWorkflowname.aspx?TemplateID={030c0f5b-f4be-4c32-9fe6-d1fbf18080e1}&Source=http%3A%2F%2FyourServer%2Fsites%2FyourSite%2F%5Flayouts%2Fworkflow%2Easpx

For Standard and Enterprise: (InfoPath forms)

http://yourServer/sites/yourSite/_layouts/IniWrkflIP.aspx?TemplateID={6bc58ac2-b39c-4e35-a644-43335e966291}&Source=http%3A%2F%2FyourServer%2Fsites%2FI%2F%5Flayouts%2Fworkflow%2Easpx

The GUID in the URL is the unique ID for your workflow.

 

For 2013:

SharePoint 2013 supports two kinds of workflows, 2010 and 2013. As a result we end up with three ways to launch a workflow. The first two are similar to the 2010 URLs listed above. Only SharePoint 2010 style workflows are available in Foundation. 2013 style workflows are only available in Standard and Enterprise if your server administrators have installed support for them.

For Foundation 2013 and SP 2010 style workflows: (ASPX forms)

I'm assuming (a dangerous thing to do!) that the URL is similar to 2010's. In any case we will just be copying the URL.

For Standard and Enterprise 2013 and SP 2010 style workflows: (InfoPath forms) 

https://yourServer/sites/yourSite/_layouts/15/IniWrkflIP.aspx?TemplateID={b5760949-b13a-4348-a309-65a01f8fbde7}&Source=https%3A%2F%2FyourServer%2Fsites%2FyourSite%2F%5Flayouts%2F15%2Fworkflow%2Easpx

For SharePoint 2013 workflows without initiation forms started from a JavaScript function call:

javascript:StartWorkflow4('7032d6a6-66e0-4c22-9483-2971b90b0e64', '', '')

For SharePoint 2013 workflows with or without initiation forms started from a URL:

https://yourServer/sites/yourSite/wfsvc/20a711570d0549ff83adafde04bce160/WFInitForm.aspx?TemplateID={7032d6a6-66e0-4c22-9483-2971b90b0e64}&WF4=1&Source=https%3A%2F%2FyourServer%2Fsites%2FyourSite

 

Steps to Create Links for Workflows in General

No matter with version or edition, if you are working with hyperlinks to start workflows your links will be created by copying the URL to the workflow and using it to launch the workflow from Quick Launch, an anchor tag (<A>), an INPUT tag or a BUTTON tag.

Copying the URL or JavaScript:

  1. For SharePoint 2010: Click Site Actions, View All Site Content. (or click All Site Content in the Quick Launch area)
    For SharePoint 2013: Click Settings (gear) and Site Contents. (or click Site Contents in the Quick Launch area)
  2. Click Site Workflows. (top right corner of page)
  3. Right-click the workflow and click Copy Shortcut. (or right-click the workflow, click Properties and copy the URL from there.
  4. If the copied link is a URL and not JavaScript:  (JavaScript will only be found for SharePoint 2013 style workflows that do not have an Initiation Form.)
    1. Paste the URL in to Notepad or other text editor.
    2. Remove the absolute part of the path (the http://servername). This is not required, but is a best practice.
      https://yourServerName/sites/yourSite/_layouts/15/IniWrkflIP.aspx?TemplateID={b5760949-b13a-4348-a309-65a01f8fbde7}&Source=https%3A%2F%2FyourServerName%2Fsites%2Ftraining%2F%5Flayouts%2F15%2Fworkflow%2Easpx
    3. Edit the URL after &Source to the URL where you want the user to land after starting the workflow. (Usually the same page they started from, but could be an "after the workflow instructions" page.)
      /sites/yourSite/_layouts/15/IniWrkflIP.aspx?TemplateID={b5760949-b13a-4348-a309-65a01f8fbde7}&Source=%2Fsites%2Ftraining%2FSitePages%2FFurthreInstructions%2Easpx
      Notes: %2F  = "/" and %2E = "."
    4. Copy the edited URL.

 

Adding a link via Quick Launch

I won't add all of the details here, but basically:

  • For 2010 team sites: Site Actions, Site Settings, Quick Launch
  • For 2010 publishing sites: Site Actions, Site Settings, Navigation, Current Navigation
  • For 2013 team sites: Settings (gear), Site Settings, Quick Launch
    or click EDIT LINKS in the Quick Launch area, click +link 
  • For 2013 publishing sites: Settings (gear), Site Settings, Navigation, Current Navigation

 

Adding Links via HTML

You can add custom HTML to Wiki pages, ASPX pages, Links lists and Content Editor Web Parts.

<input type="Button" onclick="window.location='yourCopiedUrlGoesHere'" value="click me">

<button type="Button" onclick="window.location='yourCopiedUrlGoesHere'" >click me</button>

<a href="yourCopiedUrlGoesHere">click me</a>

 

Adding Links via JavaScript

This option only applies to SharePoint 2013 and only for 2013 style workflows without Initiation Forms. (i.e. no user interaction before the workflow starts.) If you right-click a workflow link in Settings, Site Contents, Site Workflows (workflow.aspx), click Properties and see JavaScript instead of a URL it will probably look like this:
  javascript:StartWorkflow4('7032d6a6-66e0-4c22-9483-2971b90b0e64', '', '')

The nice thing about launching a workflow from StartWorkflow4 is that it is done using a CSOM web service call and does not cause the user to move to another page. Just click, and the workflow starts. The problem for us is that the StartWorkflow4 function is not available from every page in SharePoint. It's only available from workflow.aspx. To duplicate the code from that page you will need to add a link to a SharePoint JavaScript library and copy some JavaScript code from the workflow.aspx page.

The following assumes you are editing an ASPX page in SharePoint Designer, or you have placed the code in a text file and linked to that text file from a Content Editor Web Part.

Steps:

  1. Open SharePoint Designer 2013 and the open your site.
  2. If you are directly editing a page, open that page for editing. (You may need to click Advanced Mode in the ribbon.)
  3. If you are using a Content Editor Web Part for the code:
    1. Click Site Assets (could also use Site Pages or any other library).
    2. Right-click in the white space in the file list area and click HTML.
    3. Select all of the HTML and delete it.
  4. Add a link to the workflowservices.js library:
      <script type="text/javascript" src="/_layouts/15/sp.workflowservices.js"></script>
  5. Add a control to fire the JavaScript that you copied from the workflow page:

    <input type="Button" onclick="javascript:StartWorkflow4('7032d6a6-66e0-4c22-9483-2971b90b0e64', '', '')" value="click me">

    <button type="Button" onclick="javascript:StartWorkflow4('7032d6a6-66e0-4c22-9483-2971b90b0e64', '', '')">click me</button>

    <a href="" onclick="javascript:StartWorkflow4('7032d6a6-66e0-4c22-9483-2971b90b0e64', '', '') ; return false;">click me</a>
  6. Visit the Site Workflow page: Settings (gear), Site Contents, Site Workflows.
  7. Either use the browser's View Source command or press F12 and use the DOM explorer to view the HTML of the page.
  8. Search for StartWorkflow4.
  9. Browse backwards from there and find the previous <script… tag and copy from that <script tag to the matching </script> tag.
  10. Paste this into your SharePoint Designer file.
  11. Save the file.
  12. If you are directly editing a page, go to a browser and test the link.
  13. If you are using a Content Editor Web Part for the code:
    1. Go to the browser, navigate to the page where you would like to have the link.
    2. Edit the page.
    3. Insert a Content Editor Web Part.
    4. Edit the web part and in the properties panel enter the URL to your code page. Something like:
      https://yourServer/Sites/yourSite/SiteAssets/WorkFlowLinkCode.html
    5. Click OK in the properties panel.
    6. Save the page and test the link.

 

Enjoy!

 

 

Note: The OffWFCommon Feature

I have only done limited testing here… so buyer beware, and only do this on a test or dev farm.

I wanted to create a SharePoint Designer workflow that used ASPX forms instead of InfoPath forms as they were easier to customized for this project. I simply deactivated the OffWFCommon feature (by GUID), closed and reopened SharePoint Designer and then created a new workflow, which magically had ASPX forms. Not knowing what the side effects were, I reactivated the feature as soon as the workflow was written. This is a Site Collection level feature. As it is a hidden feature, you will need to use STSADM, PowerShell or code to activate or deactivate it.

Note: Even if it is on the server, activating this feature won't give you usable InfoPath forms on SharePoint Foundation!

Using STSADM:
   stsadm -o deactivatefeature -id C9C9515D-E4E2-4001-9050-74F980F93160 -url <url>

Using PowerShell:
   Disable-SPFeature -Identity c9c9515d-e4e2-4001-9050-74f980f93160 -url <url>

If you are curious, the feature lives here: (14 for 2010, 15 for 2013)
  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\OffWFCommon

 

.

10/23/2015

SharePoint: Set a Calculated Hyperlink Column from a Workflow

The following applies to SP 2010 and SP 2013 and should work in SP 2007.

You want a calculated column for a hyperlink, but can't create one. (you can't embed working HTML into the calculation.) So… you consider a workflow to create the data for a hyperlink column.

Some things in SharePoint are obvious, while others are not. Setting a calculated hyperlink field to a new URL from a workflow is one of the not so obvious. When you use the "Update List Item" action, click "this list", click Add and the "…" you get an Edit Hyperlink dialog box. While you can type manual text and URL entries, you can't build an expression. Your second choice is to click fx set a value from a variable. The problem is that this is not a simple string. The string in the variable needs to match this pattern, which includes a comma and one space:
    http://yoururl, your display text

 

Assumptions for the walkthrough:

  • You have a list with a course ID column named ID.
  • You have a course title column named Title.
  • You have an empty Hyperlink column named TheLink.

 

Steps:

  1. Open your site in SharePoint Designer 2010 or 2013 as appropriate.
  2. Click Lists and Libraries and click your list.
  3. Click the List Workflow button in the ribbon.
  4. Name your workflow and in SPD 2013 set the Platform Type to SharePoint 2010 or 2013 as desired..
  5. Click OK.
  6. Click the Action dropdown and click Set Workflow Variable.
    image
  7. Click workflow variable and create a new variable with a name like "LinkText", set the Type to String and click OK.
    image
  8. Click value and click the "" button.
  9. Create a string that will build your URL and your description, separated by a comma and a space. Click Add or Change Lookup to insert data from other columns. Then click OK.
    image
  10. Click the Action dropdown and click Update List Item. (for 2013: Set Field in Current Item)
    image
  11. Click this item, click Add, and select your hyperlink column. (for 2013: Click field and pick your hyperlink column and then click value and pick your variable.)
    image
  12. Click the fx button, select Workflow Variables and Parameters and then select your variable and click OK.
    image
  13. Click OK.
  14. Click Publish (in the ribbon).
  15. Test the workflow.
    1. Return to your list.
    2. Checkmark a list item.
    3. Click the ITEMS tab and click Workflows.
    4. Click the name of your workflow and click Start.
    5. Click the URL column and confirm that the link works.
  16. You will probably want to return to Designer and change the Workflow Settings to start the workflow when an item is created and when an item is changed.

 

 

.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.