# \[APP\]\[Pro\] Simple (Sys) LOG - Use this app for Simple (Sys) Logging

**URL:** <https://community.homey.app/t/app-pro-simple-sys-log-use-this-app-for-simple-sys-logging/77533>\
**Category:** Apps\
**Tags:** app, tools, homey-pro, logging, syslog\
**Created:** [March 11, 2023, 8:40pm UTC](https://community.homey.app/t/app-pro-simple-sys-log-use-this-app-for-simple-sys-logging/77533 "2023-03-11T20:40:00Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [March 11, 2023, 8:41pm UTC](https://community.homey.app/t/app-pro-simple-sys-log-use-this-app-for-simple-sys-logging/77533/7 "2023-03-11T20:41:40Z")

</div>

# Script to remove all flowcards in Flows and Advanced Flows from a certain app

Use this script to remove all flowcards from a certain app from flows and advanced flows. Lines are removed too, tokens are not.

Execute this in the [WebApi Playground](https://tools.developer.homey.app/tools/api-playground).  
_Note: Work in progress._

```auto
const version = '1.0.5';
//You need to run this script in the API Playground to really remove all flowcards.

//const flowNames = ['AddLogCards (Test)', 'DeleteCardsFlow']; // Use this line to run a few select flows by name.
const flowNames = null; // Use this line to run all flows

//const appId = 'homey:app:nl.nielsdeklerk.log'; // Will delete all cards and removed the lines for all Simple Log cards!
const appId = 'homey:app:nu.dijker.papertrails'; // Will delete all cards and removed the lines for all Papertrails cards!

const reallyExecute = false; //set this to false for a test run (in HS), true to really run (in the Playground)
//const reallyExecute = true; //set this to false for a test run (in HS), true to really run (in the Playground)

async function run() {
  const lineHolders = ['outputError', 'outputSuccess', 'outputTrue', 'outputFalse'];
  const flowGroups = ['triggers', 'conditions', 'actions'];

  let APIv3 = Number.parseInt((await Homey.system.getInfo()).homeyVersion.split('.')) >= 10;

  let afs = await Homey.flow.getAdvancedFlows();
  afs = _.toArray(afs);

  //return afs;
  if (flowNames) afs = _.filter(afs, x => flowNames.indexOf(x.name) > -1);
  afs = _.filter(afs, af=> _.find(af.cards, c=>c.ownerUri==appId));

  for(let i = 0;i<afs.length;i++) {
    const af = afs[i];
    const cardsToDelete = _.pickBy(af.cards, c=>c.ownerUri==appId);
    af.cards = _.pickBy(af.cards, c=>c.ownerUri!==appId);

    for(const key in af.cards) {
      //console.log(key);
      const card = af.cards[key];
      let lines;
      for(let j = 0;j<lineHolders.length;j++) {
        if(card[lineHolders[j]] && card[lineHolders[j]].length>0 && Object.keys(lines = _.pickBy(cardsToDelete, (c,k)=> card[lineHolders[j]].indexOf(k)>-1)).length ) {
          _.each(lines,(c,k)=> card[lineHolders[j]].splice(card[lineHolders[j]].indexOf(k),1));
          if(card[lineHolders[j]].length==0) delete card[lineHolders[j]];
        }
      }
    }
  }

  let flows = await Homey.flow.getFlows();
  flows = _.toArray(flows);

  //return afs;
  if (flowNames) flows = _.filter(flows, x => flowNames.indexOf(x.name) > -1);
  flows = _.filter(flows, af=> _.find(af.triggers, c=>c.uri==appId) || _.find(af.conditions, c=>c.uri==appId) || _.find(af.actions, c=>c.uri==appId));
    
  for(let i = 0;i<flows.length;i++) {
    const flow = flows[i];
    for(let j = 0;j<flowGroups.length;j++) {
        if(flow[flowGroups[j]] && flow[flowGroups[j]].length>0) {
          flow[flowGroups[j]] = _.filter(flow[flowGroups[j]], c=>c.uri!=appId);
          
          // _.each(lines,(c,k)=> card[flowGroups[j]].splice(card[flowGroups[j]].indexOf(k),1));
          // if(card[flowGroups[j]].length==0) delete card[lineHolders[j]];
        }
      }
  }

  if(reallyExecute) _.each(afs, async af=>{
   try {
     await Homey.flow.updateAdvancedFlow({id:af.id, advancedflow:{cards:af.cards}});
   } catch(err) {
     console.log(err);
   }
  });

  if(reallyExecute) _.each(flows, async flow=>{
   try {
     await Homey.flow.updateFlow({id:flow.id, flow:{actions:flow.actions, conditions:flow.conditions, trigger:flow.trigger}});
   } catch(err) {
     console.log(err);
   }
  }); else console.log(flows);
  return {afs, flows};
}

run().then(x=>{ if(this!=null) this.log(x)});

```

---

_[View the full topic](https://community.homey.app/t/app-pro-simple-sys-log-use-this-app-for-simple-sys-logging/77533)._
