Trying to convert list of Objects to List of numbers
I'm trying to set up a workflow that would automatically add ownership to an Admin group when a new page is created. I figured I'd first identify any pages without the Admin group as an owner. To do this, I used the queryWithSql package to extract from the Pages Governance dataset all PageIds without the admin group as an owner:
{
"results": [
{
"Page ID": "198669628"
},
{
"Page ID": "809811304"
},
{
"Page ID": "1632530999"
},
{
"Page ID": "1235494000"
},
{
"Page ID": "1465556204"
},
{
"Page ID": "1010091898"
},
{
"Page ID": "1637505344"
},
{
"Page ID": "756469963"
},
{
"Page ID": "1425968126"
},
{
"Page ID": "103381472"
},
{
"Page ID": "1692163503"
},
{
"Page ID": "380582169"
},
{
"Page ID": "150159124"
},
{
"Page ID": "1595324226"
}
]
}
This creates a list/object variable as an output.
So then the next logical step would be to add the Admin group to those pageIds, right? So I used addPageOwners from the DOMO DataSets package but the input requires a list/number input. I can't find a package that allows converting a list/object to a list/number and my efforts in creating my own package have been fruitless since I'm not very good at writing code. Are there any suggestions in this process?
Best Answer
-
Watch the attached video, but if you create a new function with this code (written by ChatGPT) and have the input be your dataset rows object list and the output be a list of strings, you'll get what you want.
function extractPageIDs(pageObjects) {
return pageObjects.map(obj => obj.PageID);
}0
Answers
-
Jarren, I would use the "Loop Over Dataset" workflow template.
You'll need to modify the query dataset shape to include your query, then you'll need to define your current row object, then on the "take action on current row" shape you'll need to add the user to the page.
If the Add User To Page function wants a number, the easiest thing to do would be to cast it to an integer in your query.
I'm happy to go into more detail on any of those steps if you'd like.
0 -
Hey @DanHendriksen
Thank you for the reply. Using the "Loop Over Dataset" template:
My current query is "SELECT CAST("Page ID" AS LONG) FROM dataset WHERE "Owner User ID" NOT LIKE '%1153317885%'" which creates a list/object output titled datasetRows
I'm not sure what to do on the "Get the Current Row" portion but when I enter the datasetRows output with index 0 I get the same results and null results with any other index.
For 'Take Action on the Current Row', I use the 'addPageOwners' package since there wasn't already one in place. The input requires a list/number but the workflow so far has only generated list/object or objects.
So how can I convert the results from datasetRows from a list/object to a list/number?
Thank you in advance
0 -
So, you're making progress. This is awesome! The way you use the test function with lists isn't intuitive, so don't worry about that.
If the "Test" function is giving you back what you want, which should be a list of objects that each includes a key value pair of Page ID and it's correlated ID, then you're good! All you need to do is edit the currentRow variable from the Variables list, add a child and then you'll be able to map that child to the function that wants a Page ID.
One thing to note - your variables, and their children, can't have spaces in them. So make sure in you're query you do something like ** as PageID ** (notice the lack of a space) so the child value doesn't have a space in it.
0 -
Results using queryWithSql:
{
"results": [
{
"PageID": "198669628"
},
{
"PageID": "809811304"
},
{
"PageID": "1632530999"
},
{
"PageID": "1235494000"
},
{
"PageID": "1465556204"
},
{
"PageID": "1010091898"
},
{
"PageID": "1637505344"
},
{
"PageID": "756469963"
},
{
"PageID": "1425968126"
},
{
"PageID": "103381472"
},
{
"PageID": "1692163503"
},
{
"PageID": "380582169"
},
{
"PageID": "150159124"
},
{
"PageID": "1595324226"
}
]
}Results from getObjectFromList:
{
"object": {
"results": [
{
"PageID": "198669628"
},
{
"PageID": "809811304"
},
{
"PageID": "1632530999"
},
{
"PageID": "1235494000"
},
{
"PageID": "1465556204"
},
{
"PageID": "1010091898"
},
{
"PageID": "1637505344"
},
{
"PageID": "756469963"
},
{
"PageID": "1425968126"
},
{
"PageID": "103381472"
},
{
"PageID": "1692163503"
},
{
"PageID": "380582169"
},
{
"PageID": "150159124"
},
{
"PageID": "1595324226"
}
]
}
}I added "PageID" as a child
I still can't add the list of PageIDs since it's looking for a list/number variable.
Editing the child doesn't allow an option for list/number.
0 -
I'm going to make a quick video for you - stand by.
0 -
Watch the attached video, but if you create a new function with this code (written by ChatGPT) and have the input be your dataset rows object list and the output be a list of strings, you'll get what you want.
function extractPageIDs(pageObjects) {
return pageObjects.map(obj => obj.PageID);
}0 -
That package you're using to add Page Owners - that was one that was created for use with the Page Governance Workflow Template.
It looks like the function wants a object with the new owners user ID and the type, which will either be USER or GROUP (depending on whether it's a user a group). You'll probably need to create a similar custom function for getting your data in the right format, but you may already have it that way. I don't know what all you've got going on in your workflow.0 -
@Jarren - Are you good here?
0 -
@DanHendriksen Not yet…It looks like I'm gonna need to get a little more creative with creating the list. The function chat GPT provided couldn't be used in the tile request the list/number for pageID.
0 -
@Jarren - you would put the function I shared with you as a step in between. You query the dataset to get your list of objects, you use that function to turn it in to a list of PageID's, then you pass that list to the Governance Function.
Does that make sense?
0 -
@DanHendriksen Sorry I misspoke. I created a new package using the function provided. I added that function after the query sql. I used the output of the query as the input to the function. This results in the following error:
{
"status": 404,
"statusReason": "Not Found",
"message": "This function FAILED. The return was null. The function that failed was: extractPageIDs. The standard out for this function was: FunctionExecutionLog(log=[TypeError: Cannot read properties of undefined (reading 'map')\n at extractPageIDs (/var/task/function.js:5:25)\n at execute (/var/task/executor.js:46:44)\n at Object.<anonymous> (/var/task/executor.js:66:1)\n at Module._compile (node:internal/modules/cjs/loader:1358:14)\n at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)\n at Module.load (node:internal/modules/cjs/loader:1208:32)\n at Module._load (node:internal/modules/cjs/loader:1024:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)\n at node:internal/main/run_main_module:28:49]) For more information about this execution please look at -> packageId: c5911fa3-342b-4768-a4b6-20600319d673 version: 1.0.0",
"toe": "X2ZNVMFG24-W8XTB-36XSI"
}I used ChatGPT to diagnose the error and ended up going down a rabbit hole, several times with several new chat iterations, which didn't provide the results I need to input pageIds into the governance tile. I'm guessing I'll need to create several function to slowly extract the information one step at a time; I just haven't been able to get back to it yet.
0 -
Interesting. Sorry about that. I'd guess it's some nuance the syntax of "PageID". I copied and pasted your object list into the function and I got a list back just fine. Did you try testing it in CodeEngine prior to deploying? It should be a singular step.
0 -
Here's what I have for Code Engine:
Function with Input:Output:
Test:
Instead of manually inputting the PageIds like you did in your video, I enter the results from the queryResults:
However, it works perfectly when I manually input the PageIDs, as you demonstrated in the video.
When I deploy the workflow with the same function I get the following results:
0
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.8K Visualize
- 2.5K Charting
- 731 Beast Mode
- 55 App Studio
- 40 Variables
- 682 Automate
- 175 Apps
- 451 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 122 Manage
- 119 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 107 Community Announcements
- 4.8K Archive