Skip to main content

Fixed: "There's Something Wrong with the Pasted Code" in Power Apps Studio

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

In Power Apps Studio, copying a control puts its code on the clipboard, and pasting creates a control from that code. If you copy anything else in between, such as a formula, the paste fails with There's something wrong with the pasted code. Check the code and try again. The fix is to copy the control again right before you paste it.

What I Was Doing​

In the Career Development Plan app, every screen that shows SharePoint data got a Refresh button in its header (Part 8). I built the button once, on the My Plan screen, and then copied it to the other screens' headers (How to Copy and Paste Controls Between Screens). For each screen:

  1. Paste the button on the header container (... → Paste).
  2. Rename the copy.
  3. Paste that screen's formula into the copy's OnSelect.

The first screen worked.

What I Expected​

Pasting on the next screen's header would create another copy of the button.

What I Got​

Studio showed an error instead, and no copy:

An Error dialog reading There's something wrong with the pasted code. Check the code and try again., with Show more and a Close button

Show more opened the details:

The same Error dialog expanded, with Show less and a Details box reading (1,47) : error PA1001 : An error occurred while parsing PaYaml. Error code: YamlInvalidSyntax; Reason: While scanning a plain scalar value, found invalid mapping., followed by a Note

Details
(1,47) : error PA1001 : An error occurred while parsing PaYaml. Error code: YamlInvalidSyntax; Reason: While scanning a plain scalar value, found invalid mapping.

Note:
Make sure to use the Source Code schema, which is the only supported format. To learn more: https://go.microsoft.com/fwlink/?linkid=2299600

The details box also ends with a session ID, which isn't needed here.

What I Checked​

The details talk about parsing PaYaml, so Studio was reading the paste as code. I looked at what I'd copied last. After pasting the first copy, I'd copied the first screen's formula and pasted it into OnSelect. The clipboard held that formula, not the button.

Why It Happens​

Microsoft's code view article explains how copy and paste work in Studio (Use code view for canvas app controls):

  • Copying a control copies its code, in YAML.
  • Pasting creates a new control from that code, and Studio validates the code first. Microsoft says to use the YAML format that Studio generates.
  • Pasting goes through the browser's clipboard.

So the paste didn't paste "the last control I copied". It pasted whatever was on the clipboard, and a Power Fx formula isn't valid control code. The Source Code schema in the note is the current format of that code (View source code files for canvas apps).

The Fix​

Copy the control again, then paste. On the first screen I selected ... on the button → Copy, went back to the next screen's header and selected ... → Paste. If you paste formulas in between, copy the control again before each paste.

After the Fix​

The paste worked. The copy appeared at the end of the header with _1 added to its name, next to the header's other controls:

Tree view of the My Team screen with conHeaderMTS holding btnBackMTS, lblTitleMTS, btnRefreshMTS and the pasted btnRefreshMPS_1, and the canvas header showing two Refresh buttons

That header already had its own button by then. I pasted this extra copy for the picture and removed it again with Undo (Ctrl+Z).

Common Mistakes​

MistakeWhat happensDo this instead
Copying a formula between pastesThe next paste failsCopy the control again before each paste
Pasting text from a blog post in Tree viewThe same errorPaste formulas in the formula bar, controls in Tree view
Editing copied code by hand before pastingValidation can failPaste the code Studio generated

Troubleshooting​

SymptomLikely causeFix
There's something wrong with the pasted codeThe clipboard holds something other than a controlCopy the control again
Paste does nothing at allThe browser blocks clipboard accessAllow clipboard access for Power Apps, as Microsoft's code view article describes
The copy lands in the wrong containerPaste goes into the container you pasted onUse ... → Paste on the container you want, or Reorder

FAQ​

Can I paste code that someone sent me?​

Yes, if it's control code that Studio generated. Microsoft's code view article covers copying a control's code to share it outside Studio.

Why does the copy get _1 in its name?​

Control names must be unique in an app, so Studio adds a number. Rename the copy for its new screen.

Conclusion​

There's something wrong with the pasted code means the clipboard didn't hold control code. Copy the control again right before pasting, especially when you paste formulas in between.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.