cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
5by5T
Frequent Visitor

Text input with custom button in Entity Form

Hello, 

 

I'm looking for some advice on how best to set up coupon functionality in Portals. I have a Dataverse table for coupon codes, and basically when a user is goes to complete their registration, they have the opportunity to apply coupons to that registration to reduce the cost (they are allowed to enter more than one coupon)

I thought I could set up a text input, with a custom button beside it to 'verify coupon', which could then use fetch xml, but I'm not sure that will work because A) I don't know if I can add a button right below a field in an entity form, and B) if it is a valid coupon it needs to then add a relationship to that coupon and display it in a subgrid, I'm just not sure it's possible to refresh the session to display the applied coupons. 

If you're a pro out there and you have any suggestions for how to go about adding this functionality please comment. I would really appreciate some help on this.

1 ACCEPTED SOLUTION

Accepted Solutions
chleverenz
Super User
Super User

Hi @5by5T ,

basically, you store your coupons in a custom table, i suppose. May be, they have a lifetime and box which says, that this coupon was already used or something like that.

 

You can verify and check the coupons via the web api of portals ( https://docs.microsoft.com/en-us/powerapps/maker/portals/web-api-overview ). This enables you to to everything via javascript. And this already is the problem. If the user checks the traffic he knows, how coupons are treated and could just try out a lot of them via custom clientcode.

A better approach would be for me to create a new custom table for generating the couponrequests (this table may/should be linked to the table where the coupons are applied to). When a new entry is created in that table you could run a plugin or workflow or whatever to verify the coupon and check the coupon on the new table as valid (or not 🙂 ) and also mark the coupon as used in your coupontable.

The result of this could be shown in a subgrid of your table. You should setup creation and editing of the coupons because when there was a misspelling in the couponcode, the user should be able to correct it 🙂

 

So, a lot of text, hopefully it points you in solution direction,

 have fun,

  Christian

View solution in original post

5 REPLIES 5
chleverenz
Super User
Super User

Hi @5by5T ,

basically, you store your coupons in a custom table, i suppose. May be, they have a lifetime and box which says, that this coupon was already used or something like that.

 

You can verify and check the coupons via the web api of portals ( https://docs.microsoft.com/en-us/powerapps/maker/portals/web-api-overview ). This enables you to to everything via javascript. And this already is the problem. If the user checks the traffic he knows, how coupons are treated and could just try out a lot of them via custom clientcode.

A better approach would be for me to create a new custom table for generating the couponrequests (this table may/should be linked to the table where the coupons are applied to). When a new entry is created in that table you could run a plugin or workflow or whatever to verify the coupon and check the coupon on the new table as valid (or not 🙂 ) and also mark the coupon as used in your coupontable.

The result of this could be shown in a subgrid of your table. You should setup creation and editing of the coupons because when there was a misspelling in the couponcode, the user should be able to correct it 🙂

 

So, a lot of text, hopefully it points you in solution direction,

 have fun,

  Christian

5by5T
Frequent Visitor

@chleverenz  Thank you for this! This is a helpful start. 

My follow up question would be if using the Web API would allow for automatic refresh? If the coupon is valid, I want it to add to the subgrid, but when I have tried this before using HTTP Request with Power Automate, I was able to get a response to the portal, but even though the record was added to the subrid, it didn't show on the screen unless you navigated away and the back again. Does it work differenlty with the Web API to your knowledge?

chleverenz
Super User
Super User

Hi @5by5T ,

this is an excellent point. When you make a request over the api, you create or modify data in the dynamics environment. The page will not be reloaded and therefor the subgrid will stay as it is.

 

I actually do not know, whether there is a method to refresh the subgrid. When you create entries for the subgrid, it is refreshed without page reload. So i assume there is a method but i have no idea, whether ithis one is official.

Another point on this is, that the web api and the table must not be on the same cache track. It happens frequently to me, that i change data via the webapi and reaload the page and do not see a diffrence, because the tabledata is still assumed to be valid. I thing this is not happening for subgrids as the data will always be read (hopefully). For this i have an easy workaround (but a workaround 🙂 )

 

You could (but i do not know whether i should recommend this) read the coupondata by your own and render the couponstuff with your own code. Then you do not have this problems at all but loose the standard subgrid stuff.

 

Hope this helps to sort your or architectural ideas,

  Christian

 

PS if you know how to refresh the subgrid i would be curious to know 🙂

5by5T
Frequent Visitor

@chleverenz  last I heard it isn't possible to force refresh the subgrid unfortunately. Thank you! Your thoughts have been super helpful and I really appreciate the input. 

Hi @5by5T 

Adding my two cents here. Even though there is no direct way to refresh the subgrid automatically. If you are planning to use only subgrid ( not SharePoint subgrid) then there is a way. 

 

In your  page localized >custom javascript 

$(document).ready(function() {
    console.log(555, "console loading");
    $(".entitylist.entity-grid").on("loaded", function() {
      setInterval(function () {
        $(".view-grid th:first a:first").trigger("click");
      }, 10000);
    });
});


Note: you can change the set interval function logic to make a refresh.

 


Hope it helps. 
------------

If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

 

 

 

Helpful resources

Announcements
Welcome Super Users.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (1,964)