# Flex Repeater Script

**URL:** <https://forum.inductiveautomation.com/t/flex-repeater-script/25052>\
**Category:** Ignition\
**Created:** [May 16, 2019, 10:06am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052 "2019-05-16T10:06:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![souxifou](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@souxifou](https://forum.inductiveautomation.com/u/souxifou)\
**Post date:** [May 16, 2019, 10:06am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/1 "2019-05-16T10:06:23Z")

</div>

Hi,

On my vision project i’m using a project script to fill my canvas with two different template.

I’d like to do the same in perspective, is it possible to do it with a flex repeater ?  
If yes some one have an example of script who fill the flex repeater.  
Because according to the data in my request I would like to use different templates and pass different values in my instances

Thanks

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 16, 2019, 2:41pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/2 "2019-05-16T14:41:59Z")

</div>

The Flex Repeater requires one or more instances of a single “template” View, which you can send parameters to in order to make each templated View meaningful. You may not specify multiple templates via the `FlexRepeater.props.path` property.

If you need two different Views, just use the Embedded View component twice.

---

<div class="post-metadata">

**Author:** ![souxifou](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@souxifou](https://forum.inductiveautomation.com/u/souxifou)\
**Post date:** [May 17, 2019, 1:40pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/3 "2019-05-17T13:40:59Z")

</div>

> [@cmallonee](#):
>
> The Flex Repeater requires one or more instances of a single “template” View, which you can send parameters to in order to make each templated View meaningful. You may not specify multiple templates via the `FlexRepeater.props.path` property.
> 
> If you need two different Views, just use the Embedded View component twice.

Alright thanks, so you think it's impossible to do this in perspective : (my vision project)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/cbbed71b59dc965f03601328a598f83366e9446e.png)

By the way is possible to have x template A or B in row successively

Thanks you very much cmallonee for all your answers during this week

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 17, 2019, 2:36pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/4 "2019-05-17T14:36:18Z")

</div>

What you posted actually ~~might be~~ is 100% possible, but only if you stretch your idea of a “template”.

Here’s what I would do (just as a concept - you’ll want to tinker with the settings):

1. Make one View, named UserResponse, which uses a Flex Container in column mode.
2. UserResponse should have a PARAM key `left_or_right`, which I guess you could default to “left” or “right”. It should also have PARAMs for `name` and `message`.
3. In UserResponse, place two Flex Containers and set them both to row mode.
4. In `UserResponse.root.FlexContainer` AND `UserResponse.root.FlexContainer_0`, place three Flex Containers,
5. In both `UserResponse.root.FlexContainer` AND `UserResponse.root.FlexContainer_0` set the SECOND Flex Container to have a `props.style.backGroundColor`. These second Flex Containers should also have Labels placed in them which are bound to `name` and `message`.
6. Bind this new background property with an expression something like this `if({self.view.left_or_right}=="left","#ffffff","#aaaaaa")`
7. Bind `UserResponse.root.FlexContainer.FlexContainer.position.basis` to the following expression: `if({self.view.left_or_right}=="left","0px","100px")` and bind `UserResponse.root.FlexContainer.FlexContainer_1.position.basis` to `if({self.view.left_or_right}=="left","100px","0px")`
8. Do the same for `UserResponse.root.FlexContainer_0.FlexContainer.position.basis` and `UserResponse.root.FlexContainer_0.FlexContainer_1.position.basis`

Now, you can use that single View as your template, and its color AND position are determined by the parameter you pass it. When a new response is “posted” you just add a new object to the existing FlexRepeater.props.instances array which includes which user (`left_or_right`) posted the message, the `name` of the user, and the `message` they posted.

---

<div class="post-metadata">

**Author:** ![souxifou](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@souxifou](https://forum.inductiveautomation.com/u/souxifou)\
**Post date:** [May 20, 2019, 9:55am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/5 "2019-05-20T09:55:01Z")

</div>

Thanks you a lot !

Can you explain me how this works :

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f0f0bc22d0b616c6c28e675fb2c924d8a58586eb.png)  
I’d like the message height depends of the message size

Also I’d like to give my user the possibility to send pictures, on vision used :  
system.file.openFile()  
to upload picture and saving it in my datebase as bytes.  
Should I do the same in perspective or should I use the " File upload " component ?  
By the way how it works ?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 20, 2019, 2:21pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/6 "2019-05-20T14:21:55Z")

</div>

Okay, that’s a lot to cover, but here we go:

**Message height dependent on message length:**  
That’s going to be the tough part. What you’ll most likely need to do is make sure that the `useDefaultViewHeight` of the Flex Repeater is set to `True`, and you’ll need to bind the `props.height` of the template View to an expression which measures the length of the incoming message. I’ll leave the calculations to you.

Perspective requires you to use the File Upload Component for uploading files. `system.file.openFIle()` will execute on the Gateway, not the local Session, so you’d be opening a file on the Gateway.

**Using the File Upload Component:**

1. First, check out this page of the [docs](https://docs.inductiveautomation.com/display/DOC80/Perspective+-+File+Upload#expander-control-1274696644).
2. You’ll want to use `event.file.copyTo()` as part of the `onFileReceived` Event to save the uploaded picture to the Gateway (make sure the directory you want to save to is already in place - I recommend a new directory for each project in `C:\Program Files\Inductive Automation\Ignition\webserver\webapps\main`).
3. Each Message template should now also have an Image Component placed within it, and the Message template should have a new param named `source`.
4. Bind `Image.props.source` to the `View.params.source` param AND you’ll need to include the path to the file.
5. Bind `Image.position.basis` to the following expression: `if({self.view.params.source}!="","200px","0px")`.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 20, 2019, 10:25pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/7 "2019-05-20T22:25:26Z")

</div>

Also, @souxifou: there was a change in a very recent nightly which introduced a new `position.display` property for all cildren of Flex Containers which provides the exact same functionality as the expressions I provided you. For the expressions used to determine the basis of the FlexContainers which live in a FlexContainer which is in row mode, you can bind `UserResponse.root.FlexContainer.FlexContainer.position.display` to the following expression: `if({self.view.params.source}!="","true","false")` OR you can change the left\_or\_right param entirely to make everything more clear.

If you change left\_or\_right to just left\_align and pass it as a boolean value, it might make all of the expressions more clear. This would also allow you to bind `UserResponse.root.FlexContainer.FlexContainer.position.display` to `self.view.params.left_align` and exclude the logic altogether.

---

<div class="post-metadata">

**Author:** ![souxifou](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@souxifou](https://forum.inductiveautomation.com/u/souxifou)\
**Post date:** [May 21, 2019, 12:52pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/8 "2019-05-21T12:52:04Z")

</div>

> [@cmallonee](#):
>
> You’ll want to use `event.file.copyTo()` as part of the `onFileReceived` Event to save the uploaded picture to the Gateway (make sure the directory you want to save to is already in place - I recommend a new directory for each project in `C:\Program Files\Inductive Automation\Ignition\webserver\webapps\main` ).

I have an error which tell me I d'ont have access to this directory, whereas I have all permissions on this directory

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 21, 2019, 12:57pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/9 "2019-05-21T12:57:05Z")

</div>

> [@souxifou](#):
>
> I have an error which tell me I d’ont have access to this directory, whereas I have all permissions on this directory

The permissions are needed by the Gateway _ **service** _. The permissions of a user logged in on the gateway machine (you) are not relevant. Look at the user set to run the gateway service.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 21, 2019, 8:13pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/10 "2019-05-21T20:13:59Z")

</div>

For those looking to save some time:

 ![49%20PM](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4f05dc09eb27614e4db7ceec3bed5c277df0e33a.png)  
[view.json](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/94d4ddba59a18fa5fabf1acf38076d331b94651c.json) (4.2 KB)

---

<div class="post-metadata">

**Author:** ![souxifou](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@souxifou](https://forum.inductiveautomation.com/u/souxifou)\
**Post date:** [May 22, 2019, 6:32am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/11 "2019-05-22T06:32:33Z")

</div>

> [@pturmel](#):
>
> The permissions are needed by the Gateway _ **service** _

Where can I check this on the gateway ?  
Because i didn't found the settings who give me the permission to upload something as administrator

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 22, 2019, 10:41am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/12 "2019-05-22T10:41:31Z")

</div>

Who had administrator permission on the gateway to install Ignition in the first place? That’s probably the person who will have to adjust permissions on the folders in the gateway that your scripts are trying to use.

---

<div class="post-metadata">

**Author:** ![souxifou](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@souxifou](https://forum.inductiveautomation.com/u/souxifou)\
**Post date:** [May 22, 2019, 10:43am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/13 "2019-05-22T10:43:05Z")

</div>

But I am the administrator, I’m working on local session

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 22, 2019, 10:52am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/14 "2019-05-22T10:52:59Z")

</div>

Look at “Services” under your “Computer Management” tools. Find Ignition in the list. Open that and look for the user assigned to run the background service. Give that user (probably something like “LOCALSYSTEM”) write access to the folders in question. Services run with their own identity – _ **your** _ permissions as a local user are non-relevant.

I’ll let other users here help you with any further details – I’m happy to work with the copies of Windows my customers install, but I otherwise avoid Windows like the plague.

---

<div class="post-metadata">

**Author:** ![souxifou](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@souxifou](https://forum.inductiveautomation.com/u/souxifou)\
**Post date:** [May 22, 2019, 11:02am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script/25052/15 "2019-05-22T11:02:06Z")

</div>

I’ve already check this, and still not working

Thanks anyway
