Convert Butler command to Trellinator
Asked by Keith:

I'm looking to convert some commands to Trellinator but am stuck with how to start coding :)

Basically I need to do a bunch of actions based on a change to a card. In this instance when a card is added to a specific list with some criteria set do the move and post a comment.

Is this something that Trellinator can do given the Butler command limit is low comparatively?

when a card without the green "Deposit Received" label is added to list "Accepted/ Waiting Deposit", set due in 3 working days, mark the due date as incomplete, move the card to the top of list "Accepted/ Waiting Deposit", and post comment "@reply Thank you for confirming that you would like to proceed with this job! "


Answers:
author: Iain Dooley
body: [@Keith](/t5/user/viewprofilepage/user-id/4077583) this function does what you want:

<https://gist.github.com/iaindooley/f62327703716c8a25f7405b036e76d36>

except I noticed that the markDueDateIncomplete method isn't present in the "quickstart" sheet you copied initially, so copy this function to line 847 of apps/trellinator-lib/Card.gs in the script editor:

<https://gist.github.com/iaindooley/7d042116174d2cc5ffc8babeaf472ffc>

I see that "@reply" comment -- are you using BenkoBoard or BenkoDesk? That's also my product :)

If you go to here:

<http://docs.trellinator.com/>

a good place to start is with the Notification class -- that's where most of your functions will begin if they're handling notifications. Scheduled commands are a bit trickier.

You can also see hundreds (maybe more than 1000) snippets and examples I've posted on the community here:

<https://gist.github.com/iaindooley>

comments: author: Keith
body: hey [@Iain Dooley](/t5/user/viewprofilepage/user-id/1416112)

thanks that works a treat. I've added in a whole bunch of functions already :)

I can't see any functionality on the docs in the notification class to return a card object once a label has been added.

<br />

I.e. label is added, update card with xyz

Is this available or done another way?

(<http://docs.trellinator.com/module-TrellinatorCore.Notification.html>)


author: Iain Dooley
body: [@Keith](/t5/user/viewprofilepage/user-id/4077583)

typically any notification that returns something other than a card will have a containing card set on it:

```
notif = new Notification(notification);

var card = notif.addedLabel("Whatevs").card();

var card = notif.completedChecklistItem().checklist().card();

var card = notif.attachedLink().card();

var card = notif.changedCustomFieldValue().card();

var board = notif.changedListName().board();

var board = notif.addedCard().board();

var board = notif.addedCard().list().board();
```

and so on. So each thing that gets returned will have a reference to it's container (checklist, card, list, board).

BTW what's with the "@reply" in your comment, are you using BenkoBoard/BenkoDesk??


author: Iain Dooley
body: [@Keith](/t5/user/viewprofilepage/user-id/4077583) oh i should also mention that those objects are available from the notification too:

notif.board();

notif.card();

notif.listBefore();//throws InvalidActionException if no list before

notif.listAfter();//throws InvalidActionException if no list after

You can use:

Notification.expectException(InvalidActionException,e);

Notification.expectException(InvalidDataException,e);

in your catch block so that if another exception is thrown (for example InvalidRequestException) that should cause processing to halt and be retried from the ExecutionQueue you don't catch and kill it.


author: Keith
body: For @reply I'm using Sendboard

I'll give the rest a go later on.

Thanks


author: Iain Dooley
body: [@Keith](/t5/user/viewprofilepage/user-id/4077583) ah okay, SendBoard ripped off my reply syntax then ;) I know they had plans to allow replies from comments.


author: Keith
body: hey [@Iain Dooley](/t5/user/viewprofilepage/user-id/1416112)

Thanks again for your help!

<br />

Can you spot why I can't get this card to move?
> function addedLabel_DepNotReq(notification)
>
> {  
> var notif = new Notification(notification);  
> var card = notif.addedLabel().card();  
>
> try  
> {  
>
> card.label("Deposit not required");  
> card.postComment("hello");  
> card.moveTo("Ready to Program","top");  
> }  
>
> catch(e)  
> {  
> Notification.expectException(InvalidActionException,e);  
> Notification.expectException(InvalidDataException,e);  
> }  
> }
>
> Clearly I'm missing something obvious in how the methods etc are structured and interacted with.
>
> Thanks!


author: Iain Dooley
body: [@Keith](/t5/user/viewprofilepage/user-id/4077583) one note: expectException will throw an exception if it's not what was expected. You would typically only use one of them, in this case you would expect an InvalidDataException which is thrown if you try to access a label that doesn't exist on a card, but you could also check both like this:

Notification.expectException(\[InvalidDataException,InvalidActionException\],e);

anyhoo, here's how I'd write that function:

<https://gist.github.com/iaindooley/7573220968474ed842a9964d36e3ed34>