Let’s just see how this works in practice.
We differ three expression types in skybow Expression Language:
- Template – string builder, will not be play a role in today’s advent cookie
Let’s see how can we validate a form using Assignment (one-liners) expressions. Let’s say, if we need to validate a “Request note” field, in a way that it has to have more than 100 characters, but only if the current user is not a member of the SharePoint group “Managers”, we would use the following Assignment code:
[[@User.IsMemberOfGroup("Managers")]] ? true : ([[requestnotes]].length > 100)
Note how the assignment expression does not need to return a value, the evaluation result will simply be passed as a result to the filed validator.
Pro tip: We can select both field reference and helper functions from the expression elements builder on the right side, and reduce the typos and syntax errors that way.
If we would like to write the same validation expression as a function code, we could do it like on the screenshot below:
Pro tip: you can reference any other JS file in Function code expressions – such as your favorite JS framework or your own JS libraries. They can be referenced from a SharePoint Library, CDN or any other repository type – as long as the library is accessible, the reference will work.
Let’s see a bit more complex scenario, what all can be achieved using custom JS code.
Let’s say, our scenario here is to select multiple list items from a list view, and manipulate them in a batch. For that, we will need first to read the value of the “Vendor” field placed in the above the list view (in our case, through skybow List View Search component, but it could be manually or on any other way, there would be no difference).
We have a skybow Action Link “Assemble order”, which should first check if the vendor is selected (field “Vendor” has a value), and if yes, perform the batch update. Each action link has a “Condition” property. In that property, we will use a Function code expression to read the Vendor field value:
var vendor = document.querySelectorAll('[title=Vendor]'); var venvalue = vendor.options[vendor.selectedIndex].value; return(venvalue!=="0");
Note how we are using pure JS here, without any skybow “supercharging”, since we are performing a simple DOM operation.
Next, we will have an “Execute script” action to actually perform the batch update.
Note how here we are using both JSOM (SP.js namespace) both for getting current ClientContext and all currently selected items (SP.ListOperation.Selection.getSelectedItems()), bur mixing it with skybow field and context data and helper functions ([@Web.GetFirstValueForQuery() executes CAML queries on lists).
This way, you can create really powerful scenarios, and actually cross every border that comes along your way. This mixture of an easy to use, drag-and-drop-like configuration environment, and powerful development toolbox, is what makes skybow so sweet.