Welcome to our blog where will be sharing tip, tricks and detailed walk-throughs covering all areas of Dynamics 365 but primarily focused on the Field Service and Project Service Apps, Scheduling and integration using Microsoft Flow and the Common Data Service (CDS). We hope you find the blog posts useful and please feel free to comment if you would like us to elaborate on any particular area. 

Part 2: Flow integration with Dynamics Portals using Request and Response

Following on from Part 1 where I showed you how you could use the Flow Request Trigger with the Response Action to return a list of GoTo Webinars via the Premium Connector. In this part I am going to show you how we can expand on that to add a "Register" button to the grid we build from the "List Webinars" flow which in turn will call another Flow which will add the portal contact as a registrant on the webinar they have selected.

So, as in the last post, login to your Office 365 Portal to launch Flow (or via Dynamics 365) and create a new Flow from blank. Start by adding a Request Trigger but this time specify a method of "POST" rather than "GET".

Following this add a new action step, search for "webinar" and then choose "Add Registrant".

When selected, you will see that it needs 4 parameters, a Webinar Key (which we returned in our "Get Webinars" flow) and an Email, First name and Last name.

Obviously we need to pass in this information to the Request in order to then pass them onto the "Add Registrant" action. So go back to the request and select "Use Sample Payload to generate schema". This is a great little feature which allows you to put in a sample JSON object to specify the data we're expecting on the Request and then Flow which automatically generate the asssociated schema based on the JSON payload you specified. For example:

Then when you press "Done" you can see the schema is populated (note, i'd already saved this which is why i have the POST URL populated)

If you then go back into the "Add Registrant" action and click on "Email" you will see the values specified on the Request have now become available for us to add into the "Add Registrant" action. Note, for the Webinar Key you will need to select "Enter custom value" before highlighting the item in the Dynamic content.

The final "Add Registrant" action should look like:

Then, for the last step we need to return a Response. In this case, I'm simply going to return the "Status" which I get back from the "Add Registrant" call.

Now that's the Flow wrapped up we just need to amend the web template to add a button to each row in the grid which will invoke this Flow.


Template HTML Code:

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/r/bs-3.3.5/jq-2.1.4,dt-1.10.8/datatables.min.css" />

<script type="text/javascript" src="https://cdn.datatables.net/r/bs-3.3.5/jqc-1.11.3,dt-1.10.8/datatables.min.js"></script>

<div class="container">

<table id="json-data" class="table table-bordered table-hover">

<tr>

<th>Subject</th>

<th>Start Time</th>

<th>End Time</th>

<th>Description</th>

<th></th>

</tr>

</table>

</div>

<script type="text/javascript">

$(document).ready(function() {

var listWebinarsUrl = '<Your Flow List Webinars URL>';


$.ajax({

url: listWebinarsUrl,

type: 'GET',

dataType: 'json',

})

.done(function(resp) {

$.each(resp.webinars, function(i,webinar){

var newRow =

"<tr>"

+"<td>"+webinar.Subject+"</td>"

+"<td>"+webinar.StartTime+"</td>"

+"<td>"+webinar.EndTime+"</td>"

+ "<td>" + webinar.Description + "</td>"

+ "<td><button type='button' onclick='register(this);' id='" + webinar.WebinarKey + "' >Register</button></td>"

+"</tr>" ;

$(newRow).appendTo("#json-data");

})})

.fail(function() {

console.log("error");

});

});


function register(btn)

{

var webinarKey = btn.id;

var registerUrl = '<Your Flow Add Registrant URL>';

var portalContact = {

"firstname": "{{ user.firstname }}",

"lastname": "{{ user.lastname }}",

"email": "{{ user.emailaddress1 }}",

"webinarKey": "" + webinarKey + ""

}


$.ajax({

url: registerUrl,

type: 'POST',

dataType: 'json',

contentType: 'application/json',

data: JSON.stringify(portalContact)

})

.done(function (resp) {

alert('Completed');

})

.fail(function () {

alert("error");

});

}</script>

All that's left now is to log in to the Portal and register for an Event. I've created a new Flow Demo event to illustrate.

Here's the new "List Webinars" with the Register button.

I've setup my portal contact "Allan Saddler" with my email address but you can see the Registration come through after i've clicked the "Register" button.


And that's it for this blog post. Hopefully you've found this useful and gives you some ideas about what is possible using the Flow Request Trigger in conjunction with the Response action.






631 views0 comments