You can use Google Scripting to post information from a Kuali Build form to another source via API (i.e. Google Doc, Google sheet, etc) as an integration step in workflow. Below outlines the steps to take to create a basic POST integration from Kuali Build to a GoogleDoc. More information on app scripts can be found here.
Create the Doc
-
Create a new Google Doc
- Update permissions to allow anyone with the link to have access
Then you’ll need to note the unique ID for the sheet itself. You’ll need this later when we setup a google script to expose the rest api. If you look at the url of the sheet, you’ll see the ID comes at the end of the /document/d/<id>/edit
(Note: when you copy and paste this id, it should NOT include the “/edit#..” part.)
Create the Script
- Go to https://script.google.com
- Click on New Project
- Replace the contents of the Code.gs file with the code text at the bottom of this document.
- Replace the spreadsheet id in line 2 with the id of your spreadsheet. (Note: Don't delete the apostrophes to each side of the id number.)
- Click on Deploy, then New Deployment
- In the New deployment dialog, add Description, select Type as Web app. In the Configuration screen, set Execute as to Me (your email address) and set Who has access to Anyone.
- Click on Done - You’ll be prompted to Authorize access to allow your project access to your Google Account. This is what allows the script to access your document securely.
- In the final New Deployment dialog, copy the Web app URL. This is the URL you need to configure the API Integration in Kuali Build.
- Click on Done.
- Within the form I've added the below Short Text field of 'Type of Fruit TEST" - please note that I have added a custom JSON key (fruittest) for easier selection/use later in the API Integration:
- Save the field to the form template - you can wait to publish until you add the workflow step.
Create the API Integration in Build
- From your Kuali Build Dashboard click on the Kuali Build dropdown menu in the upper left corner. Click System API Integrations.
- You will find yourself on the API Integration page. Click on Add API Integration.
- Enter a name for the integration
- Set Type of Integration to Use in Workflow.
- Set HTTP Method to POST.
- Insert the URL from current web app URL into Integration URL.
- Set Authentication Type to No authentication
- In the Configure Request Body is where you can set what information is sent. For this example, I specified two fields to send - the specific Fruit field and then the Created By User info. The Label is what you want to call the field in the Body and then the Data Path is the JSON to retrieve the field (i.e. fruittest from the field we created in the prior step). The Gadget Type is then selected to match. If desired you can send additional information via the checkboxes for applicationID, documentId, formId, meta.
- Within the Header information put the Key as 'Content-Type' and Value of 'application/json' as below:
- Click Run Test. Once the test runs successfully with a Status 200, click Save.
You can now use this integration as an Integration step in the Form workflow in the next step.
Add the Integration Workflow Step
Within the Form Workflow you can then add an Integration step in the desired place to trigger this POST action to send the configured information. Within the integration you point to the newly created integration and then specify or connect the fields configured in the Request Body of the integration (which we added fruit and created by fields specifically):
Code Text for Code.gs (to insert in the script)
*PLEASE NOTE on the below code.gs*
- The var sheet code below '1NLt0F-et7pwoHH3N_LwBA6zmn8vv92PEV5TobLaTWaw' needs to be replaced with your own unique document ID as mentioned above.
- This is only a suggested code.gs - you can modify as needed and script.google could modify requirements that could make this sample no longer work as expected.
function doPost(e){
Logger.log(e)
const docId = "1NLt0F-et7pwoHH3N_LwBA6zmn8vv92PEV5TobLaTWaw"
const document = DocumentApp.openById(docId)
let body = document.getBody()
body.setText(JSON.stringify(e))
return ContentService.createTextOutput(JSON.stringify({name: "fun person"})).setMimeType(ContentService.MimeType.JSON)
}
Comments
0 comments
Article is closed for comments.