<%NOBLOCKOUTPUT%>
Set the variable varSearchType in the next block:
1 = Only search for the exact page entered in input
2 = Try lowercase if exact page isn't found
3 = Try capitalizing first letter if (option 2) all lowercase wasn't found either
<%SET:varSearchType,3%><%NOBLOCKOUTPUT%>
<%SET:varInput,<%INPUT:Name of page to search for%>%><%NOBLOCKOUTPUT%>
Page details of your search: <%GET:varInput%>
<%JAVASCRIPT:
```javascript
//Retrieve variable set in previous block for page to search
var inputString = roam42.smartBlocks.activeWorkflow.vars["varInput"];
//Retrieve variable set in previous block for search option (whether to try other variations of page name entered)
var searchVariation = "";
searchVariation = roam42.smartBlocks.activeWorkflow.vars["varSearchType"];
//Check to make sure user entered a valid option of 1, 2, or 3
if(!searchVariation){searchVariation = "1";}
if(searchVariation != "1" && searchVariation != "2" && searchVariation != "3"){searchVariation = "1";}
var pageSearch = "";
var searchVarInt = 1;
switch(searchVariation)
{
case "1": //As entered by user
searchVarInt = 1;
break;
case "2": //All lowercase
searchVarInt = 2;
break;
case "3": //First letter capitalized
searchVarInt = 3;
break;
default:
searchVarInt = 1;
break;
}
//Loop through the variations you want to search for the page name
var loopCtr = 1;
do
{
switch(loopCtr)
{
case 1: //As entered by user
pageSearch = inputString;
break;
case 2: //All lowercase
pageSearch = inputString.toLowerCase();
break;
case 3: //First letter capitalized
pageSearch = inputString.charAt(0).toUpperCase() + inputString.slice(1);
break;
}
if(pageSearch == ""){return 'No page name entered in search box';}
if(pageSearch == inputString && loopCtr != 1)
{
//console.log('Skipping query. Already searched for: ' + pageSearch);
}
else
{
var allPages = window.roamAlphaAPI.q(`
[
:find (pull ?page-found [*])
:in $ ?page-title
:where [
?page-found :node/title ?page-title
]
]
`,pageSearch);
}
if(allPages[0]){loopCtr = 4;}
loopCtr++;
}while(loopCtr <= searchVarInt);
if(allPages[0])
{
var strEmail = 'Email: ' + allPages[0][0].email;
var createdDate = new Date(0);
createdDate.setUTCSeconds(parseInt(parseInt(allPages[0][0].time) / 1000));
var strTime = 'Created: ' + createdDate.toLocaleString();
var strTitle = 'Page: [[' + allPages[0][0].title + ']]';
var strUid = 'Page ID: ' + allPages[0][0].uid;
var strURL = 'Page URL: ' + window.location.href.substring(0,window.location.href.indexOf('/page/')+6) + allPages[0][0].uid;
var strDBid = 'DB ID: ' + allPages[0][0].id;
roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(strEmail);
roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(strTime);
roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(strUid);
roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(strURL);
roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(strDBid);
roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(JSON.stringify(allPages[0][0],null,4));
return strTitle;
}else{return 'Page not found';}
%>
#42SmartBlock AlphaAPI Page Count
<%JAVASCRIPT:
```javascript
//Get all pages
var allPages = window.roamAlphaAPI.q( [ :find ?e :where [ ?e :node/title ] ] );
return 'Total pages in your Graph: ' + allPages.length;
%>
📋 Describe the SmartBlock
I have decided to put together some Javascript SmartBlocks to start building out complex queries/workflows etc. I will continue to publish these SmartBlocks as I build them the next few hours/days. I am starting simple, but part of the goal is to learn all the capabilities and hopefully teach you all how to use them too so you can build your own variations! The first one is a simple one to search for a Page and get details about it. See GitHub link in this thread to stay up to date. (this is NOT the new one they are working on... it is the old one that has been around for a while and can query/pull pages/blocks but NOT write new ones).
✅ Describe any prerequisites or dependencies that are required for this SmartBlock
None
📷 Screenshot of your #42SmartBlock workflow/template from Roam
💡 Additional Info
Continue to check back as I will continue to add new Alpha API SmartBlocks as I experiment.
✂️ Copy of your #42SmartBlock from Roam
%>
//Get all pages var allPages = window.roamAlphaAPI.q(
[ :find ?e :where [ ?e :node/title ] ]
);return 'Total pages in your Graph: ' + allPages.length;
📋 Describe the SmartBlock
I have decided to put together some Javascript SmartBlocks to start building out complex queries/workflows etc. I will continue to publish these SmartBlocks as I build them the next few hours/days. I am starting simple, but part of the goal is to learn all the capabilities and hopefully teach you all how to use them too so you can build your own variations! The first one is a simple one to search for a Page and get details about it. See GitHub link in this thread to stay up to date. (this is NOT the new one they are working on... it is the old one that has been around for a while and can query/pull pages/blocks but NOT write new ones).
✅ Describe any prerequisites or dependencies that are required for this SmartBlock
None
📷 Screenshot of your #42SmartBlock workflow/template from Roam
💡 Additional Info
Continue to check back as I will continue to add new Alpha API SmartBlocks as I experiment.