# Why Provision's Script works on every device regardless on Preset

**URL:** <https://forum.genieacs.com/t/why-provisions-script-works-on-every-device-regardless-on-preset/3098>\
**Category:** Uncategorized\
**Created:** [October 20, 2022, 7:38am UTC](https://forum.genieacs.com/t/why-provisions-script-works-on-every-device-regardless-on-preset/3098 "2022-10-20T07:38:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clxxcv](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/clxxcv/32/1013_2.png) [@Clxxcv](https://forum.genieacs.com/u/Clxxcv)\
**Post date:** [October 20, 2022, 7:38am UTC](https://forum.genieacs.com/t/why-provisions-script-works-on-every-device-regardless-on-preset/3098/1 "2022-10-20T07:38:48Z")

</div>

Hello guys, i stumbled on that problem a couple days ago, cant find the nature of that issue, but every Provision i added happen to trying change some parameters. How did i find out ? Thanks to Tags, on some script i change the tag to understand that worked, after a couple of times i notice, i didnt changed the Presets for filtering, but script provisioned anyway. After i played with tags on one device to find out some parameters to change\refresh, i opened “Devices” tab and you know what i found ? that anyhow Tags was appeared on all devices. Only Tags which was created with Provision Script

On some scripts i remove tags, add another one, sometimes tag still, sometimes tag removed (meaning that provisioning worked - but big very BUT parameter still untouched)  
for example:  
Have a Preset and Provision script  
To enable remote access for GPON Tag should be 222:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/genieacs/original/2X/8/880c0da29dafa3fc5bc52c1981bf944b8cad7424.png)

```auto
declare("Tags.222", null, {value: false});
declare("Tags.remote_control", null, {value: true});
let now = Date.now();
declare("InternetGatewayDevice.X_HW_Security.AclServices",{path: now},{value: 1});
declare("InternetGatewayDevice.X_HW_Security.AclServices.SSHWanEnable",{path: now},{value: true});

```

And for Disable i use tag 444:

```auto
declare("Tags.444", null, {value: false});
declare("Tags.remote_control", null, {value: false});
const now = Date.now();
declare("InternetGatewayDevice.X_HW_Security.AclServices",{path: now},{value: 1});
declare("InternetGatewayDevice.X_HW_Security.AclServices.SSHWanEnable",{path: now},{value: false});

```

Cant understand why that happen. Which way i should dig, and how you guys debug ?How to stop it ? or i should to reinstall the Genieacs, and configure from the begining ?

Also find out that problem appeared on all devices. Maybe that could help.

```auto
name: Error
message: Invalid parameter path
stack: |-
  Error: Invalid parameter path
      at static (/usr/lib/node_modules/lib/common/path.ts:201:39)
      at null.value (/usr/lib/node_modules/lib/sandbox.ts:230:27)
      at Huawei_Provisioning:2:1
      at Huawei_Provisioning:29:3
      at Script.runInContext (node:vm:139:12)
      at async (/usr/lib/node_modules/lib/sandbox.ts:393:18)
      at async (/usr/lib/node_modules/lib/session.ts:642:14)
      at Array.map (<anonymous>)
      at async (/usr/lib/node_modules/lib/session.ts:606:16)
      at async (/usr/lib/node_modules/lib/session.ts:1067:15)

```

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/genieacs/original/2X/f/f5e028b7fc72e5377d2f85fb541e4660d7e597e0.png)  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/genieacs/original/2X/2/27e73fc53aab7ced2faaef051b0fd4d4d97d712f.png)

---

<div class="post-metadata">

**Author:** ![Clxxcv](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/clxxcv/32/1013_2.png) [@Clxxcv](https://forum.genieacs.com/u/Clxxcv)\
**Post date:** [October 20, 2022, 12:34pm UTC](https://forum.genieacs.com/t/why-provisions-script-works-on-every-device-regardless-on-preset/3098/2 "2022-10-20T12:34:32Z")

</div>

Removed all not default Provision Scripts and Presets.  
Removed All tags from CPE.  
Added only one Tag to initiate Provisioning  
Rebooted server.

After I got another Fault:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/genieacs/original/2X/6/66b0bf1e204785f7a48f022b0aee944a3f0aaa59.png)

Begin to realise that happens bc of bootstrap.

```auto
let now = Date.now();
// Clear cached data model to force a refresh
clear("Device", now);
clear("InternetGatewayDevice", now);
let device_class=declare("DeviceID.ProductClass",{value:1}).value[0];
let serial_number=declare("DeviceID.SerialNumber",{value:1}).value[0];

log('here we have ' + device_class + ' with that S/N ' + serial_number);
  if (device_class == "HG8546M"){
      log('Provisioning ...' + serial_number);
      declare("Tags.HG8546M",{path: now},{value:true});
  } else {
      declare("Tags.WTF",{path: now},{value:true});
 }

```

Reconfigure script now it look like this

```auto
let now = Date.now();

// Clear cached data model to force a refresh
clear("Device", now);
clear("InternetGatewayDevice", now);
//Added that line
let provisioned=declare("Tags.Huawei_Done",{value:1}).value[0];
let device_class=declare("DeviceID.ProductClass",{value:1}).value[0];
let serial_number=declare("DeviceID.SerialNumber",{value:1}).value[0];

log('here we have ' + device_class + ' with that S/N ' + serial_number);
//Added and that one
if (provisioned == false){
  if (device_class == "HG8546M"){
      log('Provisioning ...' + serial_number);
      declare("Tags.HG8546M",{path: now},{value:true});
  } else {
      declare("Tags.WTF",{path: now},{value:true});
  }
}

```

i will update if something goes wrong.

---

<div class="post-metadata">

**Author:** ![akcoder](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/akcoder/32/11_2.png) [@akcoder](https://forum.genieacs.com/u/akcoder)\
**Post date:** [October 20, 2022, 5:24pm UTC](https://forum.genieacs.com/t/why-provisions-script-works-on-every-device-regardless-on-preset/3098/3 "2022-10-20T17:24:26Z")

</div>

Your precondition for the preset is wrong. Try this `Tags.222 IS NOT NULL`.

---

<div class="post-metadata">

**Author:** ![Clxxcv](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/clxxcv/32/1013_2.png) [@Clxxcv](https://forum.genieacs.com/u/Clxxcv)\
**Post date:** [October 21, 2022, 5:35am UTC](https://forum.genieacs.com/t/why-provisions-script-works-on-every-device-regardless-on-preset/3098/4 "2022-10-21T05:35:39Z")

</div>

Thank you that worked !  
My Upper solution for checking if there already a tag from Provisioning script - doesnt work well, error occur when device doesnt have that Tag, saying

_Cannot read properties of undefined (reading ‘0’)_

and stoping the script. While others which had that tag - passed well.

```auto
let provisioned=declare("Tags.Huawei_Done",{value:1}).value[0];
if (provisioned == false){ ...

```

is there a possible way to say Preset bootstrap “only work with devices which has no TAG at all ! and Ignore which has already any TAG” ?

---

<div class="post-metadata">

**Author:** ![akcoder](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/akcoder/32/11_2.png) [@akcoder](https://forum.genieacs.com/u/akcoder)\
**Post date:** [October 21, 2022, 4:23pm UTC](https://forum.genieacs.com/t/why-provisions-script-works-on-every-device-regardless-on-preset/3098/5 "2022-10-21T16:23:33Z")

</div>

It doesn’t work because tags aren’t an array. The reason the value of a declare would be an array is the first index of the array is the value, the second is the data type.

Put this function in your provision script and use it like so:

```auto
if (!hasTag('Huawei_Done')) {
    // Do stuff
}

function hasTag(name) {
    const result = declare(`Tags.${name}`, {value: 1});
    return result.value !== undefined;
}

```
