Workflow function
I am trying to create a workflow function and I am having issues. I am not a developer, so I need help. I finally was able to get beyond the errors but now I am getting errors when I save/deploy. Please help!
Here is the code:
const codeengine = require('codeengine');
function lookforunlocked () {
const api= '/api/social/v1/smart-alerts/disable?resourceId=${cardId}&resourceType=CARD ';
var newdisable = "true";
return codeengine.sendRequest("PUT", api, {"disable":newdisable}).catch(console.error);
}
module.exports.myFunction = lookforunlocked;
Best Answers
-
Kathy, it looks like your function is looking for a parameter called cardId (in your second line, ${cardId} is javascript to insert a variable in to a string, but your function isn't asking for any arguments.
As a non-developer also, I've had to figure this out. Let me try to explain.
Any values that you want to pass to the function as parameters, variables or arguments (devs use the term arguments) need to be included in the parenthesis after the function. So I think the first thing I notice is that you need to, at a minimum, add cardId in the parenthesis and have an input parameter (of the correct data type) that is a cardId. I would guess that is a NUMBER.Second, you have 'single quotes' around your string on the second line (where you create the const API) and it should be surrounded by ` backticks `.
Your function is called "lookForUnlocked" - in looking at the end point are you trying to enable/disable insights for non-card owners? If so, the way you have the function written is hard coded to DISABLE them, not way to enable them.
I may propose the following changes to the function:1 - add cardId as an input parameter, and make it a number
2 - change the single quotes to backticks"
3 - eliminate the newdisable variable as it's already harded coded in the API call
4 - your put appears to be incorrect, it should be a POST
If what you are after is disabling Insights on a card, the following code works (I changed the function to be named "disableCardInsights" as opposed to "lookForUnlocked", but you can call it whatever you want:←————————————CODE———————————→
const codeengine = require('codeengine');function disableCardInsights(cardId) {
const api =/api/social/v1/smart-alerts/disable?resourceId=${cardId}&resourceType=CARD
;
const body = ``;
return codeengine.sendRequest("POST", api,body).catch(console.error);
}module.exports.disableCardInsights = disableCardInsights;
←———————————-END CODE——————————>
Screenshot:
The last thing I will say is you should never deploy codeEngine packages/functions until you run them successfully in codeEngine. That is when you know your code is working. You can run it by hitting the large play button next to the function in the drop down, or by hitting the small green play button in "the gutter" (as my engineers call it) which should up directly adjacent to the code line numbers.
If that's what you're after, hopefully my quick and dirty breakdown helps make sense. I had to write a lot of these before I had any level of proficiency. I will also request our team make this function in a global package. My goal is for nobody to have to write a custom function to talk to an internal Domo service.
Hope that's helpful.0 -
Thanks, that seemed to work.
1
Answers
-
Kathy, it looks like your function is looking for a parameter called cardId (in your second line, ${cardId} is javascript to insert a variable in to a string, but your function isn't asking for any arguments.
As a non-developer also, I've had to figure this out. Let me try to explain.
Any values that you want to pass to the function as parameters, variables or arguments (devs use the term arguments) need to be included in the parenthesis after the function. So I think the first thing I notice is that you need to, at a minimum, add cardId in the parenthesis and have an input parameter (of the correct data type) that is a cardId. I would guess that is a NUMBER.Second, you have 'single quotes' around your string on the second line (where you create the const API) and it should be surrounded by ` backticks `.
Your function is called "lookForUnlocked" - in looking at the end point are you trying to enable/disable insights for non-card owners? If so, the way you have the function written is hard coded to DISABLE them, not way to enable them.
I may propose the following changes to the function:1 - add cardId as an input parameter, and make it a number
2 - change the single quotes to backticks"
3 - eliminate the newdisable variable as it's already harded coded in the API call
4 - your put appears to be incorrect, it should be a POST
If what you are after is disabling Insights on a card, the following code works (I changed the function to be named "disableCardInsights" as opposed to "lookForUnlocked", but you can call it whatever you want:←————————————CODE———————————→
const codeengine = require('codeengine');function disableCardInsights(cardId) {
const api =/api/social/v1/smart-alerts/disable?resourceId=${cardId}&resourceType=CARD
;
const body = ``;
return codeengine.sendRequest("POST", api,body).catch(console.error);
}module.exports.disableCardInsights = disableCardInsights;
←———————————-END CODE——————————>
Screenshot:
The last thing I will say is you should never deploy codeEngine packages/functions until you run them successfully in codeEngine. That is when you know your code is working. You can run it by hitting the large play button next to the function in the drop down, or by hitting the small green play button in "the gutter" (as my engineers call it) which should up directly adjacent to the code line numbers.
If that's what you're after, hopefully my quick and dirty breakdown helps make sense. I had to write a lot of these before I had any level of proficiency. I will also request our team make this function in a global package. My goal is for nobody to have to write a custom function to talk to an internal Domo service.
Hope that's helpful.0 -
Thanks Dan. Please advise. I am still having issues:
When I just copied and pasted the code. Here is the parsing error:
When I added the backticks, I am getting this:
0 -
Kathy, you fixed the backticks, which is awesome. As I mentioned in the email, the community thinks the backticks are a formatting thing and hides them. #annoying
I think the reason you're having an issue if you don't have a description. Please put in a description. The requirement for a description is something we are going to remove, but I would suspect that is your issue.0 -
Dan,
The description is in the image. That is all I am getting, and I can't save the function. I copied your code verbatim. So please let me know why I am still having an issue.
First image - your code exactly
Second image - with backticks
Both are giving me errors.
0 -
Kathy, I'm sorry about the confusion but in the screenshot it literally says "No Description Provided". Under the function name, there is a description field. Put something in the description field.
0 -
Thanks, that seemed to work.
1
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive