cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hoanvd
Helper I
Helper I

Cannot Print on SharePoint Custom Form

Hi everyone,

 

I'm customizing SharePoint Edit Form using PowerApps. I use the solution from this link. This solution guide me to create a PowerApps Component Framework including one Standard control with properties bellow:

+ Text: (multiple) text of button

+ HtmlTex t: (singleline) text to print. 

 

hoanvd_0-1616494709914.png

Image show custom properties

 

In the index.ts file, it will create a button with onclick event. inside this event, it will get HtmlText and write some javascript code lines.

hoanvd_1-1616494856215.png

Image show OnInit and OnClick event for button

 

I have packaged solution and successfully added the Print Button to my form. However, when I click this Print Button, a new browser tab open and then close immediately. Note that if I open SharePoint Form on PowerApps Studio (https://create.powerapps.com/studio/), this button works well.

 

I also have tried with different browsers (current browser: Edge) and type of apps and find out as bellow:

Chrome: Error;

IE: Work;

Canvas App (App that is not created from Customize Form on SharePoint List View): Work.

 

Another clue while testing with IE, I can see the browser of new tab pointing to this address: https://content.powerapps.com/resource/webplayer/hashedresources... . This makes me think about policies or browser restricts.

 

Thanks for reading!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
cchannon
Continued Contributor
Continued Contributor

OK, so sandboxing is a technique for IFrames that constrains the ability for IFrames to take specific actions (such as popups) in order to prevent them from creating a misleading UI and tricking users into thinking that a popup is actually from the site they are on. So what appears to be the case here is that SharePoint is sandboxing the IFrame you are putting your canvas app into, and they have omitted the allow-modals permission. I'd expect you'd see identical behavior from modal dialogs, and it's why it works in IE: because it's ancient and hasn't kept up on things like this.

 

Unfortunately, there isn't a whole lot you can do about this in a supported way. You could create your own SharePoint App that is nothing more than an IFrame which does allow modals, but that does carry some deployment headaches (you'll have to deploy to the app catalog and install in your site from there; if you don't have an app catalog you'll need to spin up a new SP site for it). Or you can post a suggestion in the PowerApps Ideas forum to point out this shortcoming and suggest that SharePoint introduce an IFrame option specially for trusted sources like PowerApps which does allow modals and other special IFrame behavior. If you do that, link it here and I will upvote it for you 🙂

 

The unsupported option is that you can dom browse up to the SharePoint IFrame and try to add allow-modals to the sandbox line. Not 100% sure if it will work, but it should be pretty easy to try. In JQuery it might look like this (although you can do it with plan JS or TS if you prefer):

$("iframe[name='{someIFrameName}']").each(function() {
    this.sandbox+=' allow-modals';
});

 Good luck!

View solution in original post

4 REPLIES 4
cchannon
Continued Contributor
Continued Contributor

Well, I am not really sure what is wrong with your code, but I can tell you what I would try for figuring it out.

 

First, look at the window you are popping onclick: it renders a popup window and injects the HTML for that window with an html onload event that calls window.print() and window.close(). I would not be surprised that different browsers handle window.print() differently and the window.close() step is preventing you from figuring out what is happening, so my first step would be to remove that onload step entirely so that the window you are popping stays open.

 

This will let you directly inspect the window: does it throw a permissions issue of some kind? does the html render consistently for different browsers? Does it look the way you expect?

 

Assuming that all checks out, you can then open a debugger window and try to put window.print() into the console. Does it work? Does it work for all browsers? Do you get a specific error/deprecation message? Hopefully when you test this it will become obvious what is going on.

Hi @cchannon ,

 

I did try removing the window.close() call and it opens a new browser tab successfully. However, it does not automatically open the print option. I continued to print this page by right mouse clicking and selecting print option, the result was as expected.

 

I see the error bellow:

Ignored call to 'print()'. The document is sandboxed, and the 'allow-modals' keyword is not set.

 

It probaly is somewhat with iframe which is generated by SharePoint Custom PowerApps form.

 

cchannon
Continued Contributor
Continued Contributor

OK, so sandboxing is a technique for IFrames that constrains the ability for IFrames to take specific actions (such as popups) in order to prevent them from creating a misleading UI and tricking users into thinking that a popup is actually from the site they are on. So what appears to be the case here is that SharePoint is sandboxing the IFrame you are putting your canvas app into, and they have omitted the allow-modals permission. I'd expect you'd see identical behavior from modal dialogs, and it's why it works in IE: because it's ancient and hasn't kept up on things like this.

 

Unfortunately, there isn't a whole lot you can do about this in a supported way. You could create your own SharePoint App that is nothing more than an IFrame which does allow modals, but that does carry some deployment headaches (you'll have to deploy to the app catalog and install in your site from there; if you don't have an app catalog you'll need to spin up a new SP site for it). Or you can post a suggestion in the PowerApps Ideas forum to point out this shortcoming and suggest that SharePoint introduce an IFrame option specially for trusted sources like PowerApps which does allow modals and other special IFrame behavior. If you do that, link it here and I will upvote it for you 🙂

 

The unsupported option is that you can dom browse up to the SharePoint IFrame and try to add allow-modals to the sandbox line. Not 100% sure if it will work, but it should be pretty easy to try. In JQuery it might look like this (although you can do it with plan JS or TS if you prefer):

$("iframe[name='{someIFrameName}']").each(function() {
    this.sandbox+=' allow-modals';
});

 Good luck!

View solution in original post

It is quite annoying. I will have to still open another tab, and tell users to manually hit Print button on browser. Thank for your support!

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Users online (36,352)