Skip to content

Clone Visual

ali-hamud edited this page Jan 3, 2019 · 6 revisions

By using clone visual API you can create a copy of existing visuals into active page.

Clone Visual

use clone visual API to clone a specific visual. It's helpful when you want to create copies of one visual with different filters.

API Definition

For a definition of IFilter please see Filters Wiki page. For a definition of IVisualLayout please see Custom layout Wiki page.

interface ICloneVisualRequest {
  // The filters which will be applied to the new visual. Default: source visual filters.
  filters?: IFilter[];

  // The layout which will be applied to the new visual.
  // Default: a best effort to put a new visual in an empty space on the canvas.
  layout?: IVisualLayout;
}

interface ICloneVisualResponse {
  // New visual name
  visualName: string;
}

Visual object has a method called clone which is defined as:

clone(request: models.ICloneVisualRequest = {}): Promise<ICloneVisualResponse>

To get a list of visual on a report please see Get-Visuals Wiki.

Code Sample

Example 1

Clone a visual as is. The new position and size of the new visual will be a best effort to put a visual on an empty space on the canvas. If you want a specific position and size, please see second example.

    visual.clone()
        .then(function (result) {
            console.log(result.name);
        })
        .catch(function (errors) {
            console.log(errors);
        });

Example 2

Clone a visual with new layout.

    let cloneRequest = {
        layout: { x: 150, y: 250 }
    };

    visual.clone(cloneRequest)
        .then(function (result) {
            console.log(result.name);
        })
        .catch(function (errors) {
            console.log(errors);
        });

Example 3

Clone a visual with new layout and a new list of visual level filters.

    const basicFilter: pbi.models.IBasicFilter = {
      $schema: "http://powerbi.com/product/schema#basic",
      target: {
        table: "Store",
        column: "Count"
      },
      operator: "In",
      values: [1,2,3,4],
      filterType: pbi.models.FilterType.BasicFilter
    };

    let cloneRequest = {
        layout: { x: 150, y: 250 },
        filters: [basicFilter]
    };

    visual.clone(cloneRequest)
        .then(function (result) {
            console.log(result.name);
        })
        .catch(function (errors) {
            console.log(errors);
        });

Limitations and considerations

  • You can clone a visual only if the report is fully rendered. That means you need to wait on 'rendered' event before calling clone visual API.

  • You can clone a visual from any page in the report to the active page.