Δευτέρα 23 Ιουλίου 2012

Sharepoint Project – Create Forms and WorkFlows Part3

Ας δούμε λοιπόν τι κάνουμε.
Πρώτα από όλα Δημιουργούμε μία βιβλιοθήκη για την δημιουργία των Αιτήσεων Αδείας
image
Επίσης Δημιουργούμε Μία βιβλιοθήκη με τον ίδιο τρόπο με όνομα Εγκεκριμένες Αιτήσεις Αδείας
Και μία βιβλιοθήκη με τον ίδιο τρόπο με όνομα Απορριφθέντες Αιτήσεις Αδείας.

Οπότε στο Site μας θα εμφανιστούν οι τρεις νέες βιβλιοθήκες

image

Στην βιβλιοθήκη Αιτήσεις Αδείας Δίνουμε δικαιώματα Contribute έτσι ώστε οι χρήστες μας να μπορούν να δημιουργήσουν νέες αιτήσεις Αδείας.

Στην βιβλιοθήκη Εγκεκριμένες και Απορριφθέντες Αιτήσεις Αδείας δίνουμε δικαιώματα Read σε όλους τους χρήστες έτσι ώστε μόνο να μπορούν να δουν τις αιτήσεις αδείας τους και να μην μπορούν να τις πειράξουν.

Στη συνέχεια Πηγαίνουμε στην Βιβλιοθήκη Αιτήσεις Αδείας > Ρυθμίσεις > Ρυθμίσεις Για προχωρημένους > Επεξεργασία Προτύπου

image

Θα Ανοίξει το πρότυπο με το Infopath

image

Αρχίζουμε λοιπόν και δίνουμε μορφή στην Φόρμα μας σύμφωνα με αυτά που θέλουμε και έχουμε αναφέρει στο Part1

Μετά από όλα αυτά λοιπόν η φόρμα θα έχει μία μορφή σαν την πιο κάτω

image

Στην φόρμα που σχεδιάζουμε κάνουμε διάφορους ελέγχους της μορφής Το έως δεν μπορεί να είναι μικρότερο από το από
Ο Εργαζόμενος δεν μπορεί να είναι κενός κλπ κλπ

Ορίζουμε το πεδίο Εργαζόμενος να παίρνει τιμές από την λίστα που έχουμε δημιουργήσει και έχουμε τους εργαζόμενους. Με φίλτρα Φέρνουμε τους Διευθυντές από την ίδια λίστα κλπ

Ήρθε η ώρα να κάνουμε τον υπολογισμό των εργάσιμων ημερών χρησιμοποιόντας το Excel που είχαμε αποθηκεύσει.

Την σύνδεση αυτή μπορούμε να την πετύχουμε διαβάζοντας το ποιο κάτω άρθρο http://www.avanadeblog.com/sharepointasg/2011/10/using-excel-services-rest-api-with-infopath-2010.html

Intro

With Excel Service REST API it is possible to get data from excel sheets. But it is also possible to send input parameter to Excel sheets with this API. Due to this you can send parameters to a calculated cell or change values in diagrams and retrieve the recalculated value or diagram.

With InfoPath 2010 it is possible to retrieve data from REST web services. In combination this can be used to retrieve data from Excel spreadsheets via the Excel Services REST API in InfoPath. In the flowing text I will describe how to use this features and combine them. As sample a simple multiplication calculator with InfoPath as user interface and Excel Services as business logic will be used.

Preparing the Excel sheet

First we need to prepare the excel sheet with formulas for our calculator. I created an Excel sheet and added the following headers and values to it:

  • Paramter1 with cell B2 as value
  • Paramter2 with cell B3 as value
  • Result with formula: =B2*B3

imageimage

As sample value each parameter will be set to 5 which will be calculated as result 25 in cell B4. Now it is important to set the parameter and result cells as named range. This makes it a lot easier to use with the REST API. Just select the cell and type the name of the range in the top left corner and hit enter. Name the ranges PARAMERER1, PARAMETER2 and RESULT. Save this excel file as "rest_demo.xlsx" in a SharePoint server document library (Excel services must be available and the enterprise feature activated in the site collection).

Preparing the InfoPath 2010 form

Open InfoPath 2010 and create a new empty form. Create 3 data fields of type text with the following names:

  • Paramter1
  • Parameter2
  • Result

Drag and drop the fields onto your InfoPath form. It will look like this:

image

Now we will prepare the REST URL to call our Excel file (See "Sharepoint 2010 - Excel Services REST API"). The first part of the URL will return the result value as HTML and will look like this:

http://intranet.contoso.com/_vti_bin/ExcelRest.aspx/Shared%20Documents/rest_demo.xlsx/Model/Ranges('RESULT')

As the result will be HTML it is difficult to extract the result value in InfoPath. InfoPath is designed to use XML trees for data sources. To force Excel Services to return the result as XML tree we will append the parameter "?$format=atom":

http://intranet.contoso.com/_vti_bin/ExcelRest.aspx/Shared%20Documents/rest_demo.xlsx/Model/Ranges('RESULT')?$format=atom

At the moment we will always receive the result value 25 because we have no parameters in our URL. The trick is now to inject values on the named ranges PARAMETER1 and PARAMETER2. This can be done by appending "&Ranges('PARAMETER1')=6&Ranges('PARAMETER2')=6" to the URL. Now it will look like this and return 36 as new result value:

http://intranet.contoso.com/_vti_bin/ExcelRest.aspx/Shared%20Documents/rest_demo.xlsx/Model/Ranges('RESULT')?$format=atom&Ranges('PARAMETER1')=6&Ranges('PARAMETER2')=6

Our URL is now ready to be used in our InfoPath calculator. Open your InfoPath form and click "Data"->"From Web Service"->"From REST Web Service":

image

Insert the URL we prepared in the steps before:

image

Add a button with text "Calculate" to your form. To bind the REST action to your button click "Manage Rules". Add a rule of type "Change REST URL".

image

Click "Insert Formula" and use the "concat" function to merge the URL. Replace the parameter values with the fields "Parameter1" and "Parameter2". It will look like this:

image

If we would now bind the result of the data connection to the result field we will always get the value 25 because the data service was only called at form load. You can disable this and add a second rule to your button after the first one. Select the action "Query for data" and choose your excel REST web service.

image

Now we will receive the right value but it will not show up on the form. Therefore we need a third rule that sets the return value of the data service to our result field. Add a new rule of type "Set a field's value". Set the value of our result field with the value of the REST web service. You can find the value in the XML tree at "fv" (field value):

image

Entry->content->ns2:range->row->c->fv

The InfoPath calculator based on excel service REST API is now ready to test. Start the form in preview mode. Insert two values in the parameter fields and press the "Calculate" button.

image