functions.database.ref & Auto ID - firebase

able to get function.database.ref to work for basic chains like this.
functions.database.ref("/following/{uid}/{followingId}").onCreate(event => {
var uid = event.params.uid;
var fromId = event.params.fromId
however I have no idea what to do when we are creating something with an autoId that has a sub branch in this case fromId.
exports.NewActMessage = functions.database.ref("/ActPosts/{uid}/messages/autoId/{fromId}").onCreate(event => {
var uid = event.params.uid; //JOSIAH SAVINO
var fromId = event.params.fromId
Whats even more challenging is the autoId is what is being created but I need to pull the "fromId" information from the branch inside of the autoId.
image

Firebase messaged me how to get first the autoId than the fromId from that like so...
exports.NewActMessage =
functions.database.ref('/ActPosts/{uid}/messages/{autoId}').onCreate(event => {
var uid = event.params.uid;
var autoId = event.params.autoId;
var fromId = event.data.val().fromId;

Related

How to retrieve related records using Dataverse client sdk?

I am using Microsoft.Powerplatform.Dataverse.Client to interact with Dataverse, i want to fetch parent and child records using single query, is this possible? Please suggest how to achieve this.
var client = _client.GetServiceClient();
if (client.IsReady)
{
var queryExpression = new QueryExpression("ParentTable")
{
ColumnSet = new ColumnSet(columns),
NoLock = true,
TopCount = 1,
Criteria = GetFilterExpression(filterColumns),
};
var parentCollectionResult = await client.RetrieveMultipleAsync(queryExpression);
entities = parentCollectionResult.Entities;
}

How to create ODataQueryOptions manually

Is there a way to use latest Odata to $filter items server-side? How can I make instance of ODataQueryOptions.
In result I would like something like this:
var filterQuery = "Id eq 1"
var context = /*How to?*/;
var request = /*How to?*/;
var options = new ODataQueryOptions(context, request);
var query = option.ApplyTo(employees);

Bad Value error with my Google Apps Script to Firebase

function tree1(){
var secret =SpreadsheetApp.openById('My Database Secret') ;
var sheet = secret.getSheets()[0];
var data = sheet.getDataRange().getValues();
var dataToImport = {};
for(var i = 1; i < data.length; i++) {
var admin = data[i][0];
var email = data[i][1];
var name = data[i][2];
var subject = data[i][3];
var year = data[i][4];
var testone = data[i][5];
var testtwo = data[i][6];
var testthree = data[i][7];
var average = data[i][8];
var progress = data[i][9];
dataToImport[email] = {
name:name,
emailAddress:email,
adminNo:admin,
Subject:subject,
Year:year,
testOne:testone,
testTwo:testtwo,
testThree:testthree,
Average:average,
Progress:progress
};
}
var firebaseUrl = "My Database URL";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl);
base.setData("", dataToImport);
}
I am attempting to use a Google Sheet App script to sync basic data for my users, using their email address as a reference.
So that when a user logs in with their email they can access test scores that the admin has.
The Database structure I would like is fairly simple that the three scores and other details are a child of the email, as you can see above.
However every time I attempt to complete the script I receive a Bad Value error.
Any ideas as to how I can remedy this problem.
Thank you in advance.

Problems with IDocumentQuery.ExecuteNextAsync()

I have standard lines of code, to fetch data with pagination. It used to work until a month ago, and then stopped. On running ExecuteNextAsync() it stops execution, and displays this following information in Output window:
DocDBTrace Information: 0 : DocumentClient with id 2 disposed.
DocDBTrace Information: 0 : DocumentClient with id 1 disposed.
Not Working Code:
var query =
client.CreateDocumentQuery(
UriFactory.CreateDocumentCollectionUri(databaseId, "TestCollection"), "select c.id from TestCollection c",
new FeedOptions
{
//MaxDegreeOfParallelism=-1,
MaxItemCount = maxItemCount,
PopulateQueryMetrics=true
//RequestContinuation = requestContinuation,
//EnableScanInQuery = true,
//EnableCrossPartitionQuery = true
});
var queryAll = query.AsDocumentQuery();
var results = new List<TDocument>();
while (queryAll.HasMoreResults)
{
try
{
var result = await queryAll.ExecuteNextAsync();
var queryMetrics = result.QueryMetrics;
if (result.ResponseContinuation != null) requestContinuation = result.ResponseContinuation;
//Do something here
}
catch (Exception ex)
{
}
}
For the same client object, Create/Update or fetching all items together is working. So JsonSerializer or DocumentClient object cannot be a problem.
Working code:
var query2 = client.CreateDocumentQuery(
UriFactory.CreateDocumentCollectionUri(databaseId, collectionName), "select * from TestCollection c",
new FeedOptions { MaxItemCount = -1 });
//.Where(l => l.Id == qId);
var testData2= query2.ToList();
This has stopped our services and their development. Any help is appreciated.
Your query is wrong.
UriFactory.CreateDocumentCollectionUri(databaseId, "TestCollection") will already let the SDK know what to query.
If you simply change
select c.id from TestCollection c
to
select c.id from c
It will work. Currently it is failing to resolve the c alias because you also have TestCollection there.
The only reason your other queries that use * are working is because you aren't using the c. there.

Pulling Docs List from Collection

I there a way to display specific collection files and URL in a spreadsheet?
I have already tried running a basic DocList Search script but I need something to be more direct. I would need the script to display File Name, Collections It belongs to, and URL.
The end goal of this project is to create a Google site that allows users to click a Image link launching a simple "Copy Function" this copy function will create a copy of that document for the user in there individual drive. However we will be doing this on a mass scale of over 1,000 documents. So pulling the information and having it more organized would be alot easier then copying the URL section out of each document and then pasting it into the scripts functions.
here is a script I wrote quite a while ago that does (a bit more than ) what you want... it shows the IDs but you can easily change it to show the urls instead.
// G. Variables
var sh = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lastrow = ss.getLastRow();
//
//
//
function onOpen() {
var menuEntries = [ {name: "generic doclist", functionName: "gendoclisttest"},
{name: "categorized list(spreadsheet/docs)", functionName: "doclistcat"},
{name: "Search DocList", functionName: "searchUI"},
];
ss.addMenu("Utilities", menuEntries);//
}
//
// Build a simple UI to enter search item and show results + activate result's row
function searchUI() {
var app = UiApp.createApplication().setHeight(130).setWidth(400);
app.setTitle("Search by name or folder name");
var panel = app.createVerticalPanel();
var txtBox = app.createTextBox().setFocus(true).setWidth("180");
var label=app.createLabel(" Eléments à rechercher :")
var label=app.createLabel(" Item to search for :")
panel.add(label);
txtBox.setId("item").setName("item");
var label0=app.createLabel("Row").setWidth("40");
var label1=app.createLabel("Doc Name").setWidth("180");
var label2=app.createLabel("Doc ID").setWidth("180");
var hpanel = app.createHorizontalPanel();
hpanel.add(label0).add(label1).add(label2);
//
var txt0=app.createTextBox().setId("lab0").setName("0").setWidth("40");
var txt1=app.createTextBox().setId("lab1").setName("txt1").setWidth("180");
var txt2=app.createTextBox().setId("lab2").setName("txt2").setWidth("180");
var hpanel2 = app.createHorizontalPanel();
hpanel2.add(txt0).add(txt1).add(txt2);
var hidden = app.createHidden().setName("hidden").setId("hidden");
var subbtn = app.createButton("next ?").setId("next").setWidth("250");
panel.add(txtBox);
panel.add(subbtn);
panel.add(hidden);
panel.add(hpanel);
panel.add(hpanel2);
var keyHandler = app.createServerHandler("click");
txtBox.addKeyUpHandler(keyHandler)
keyHandler.addCallbackElement(panel);
//
var submitHandler = app.createServerHandler("next");
subbtn.addClickHandler(submitHandler);
submitHandler.addCallbackElement(panel);
//
app.add(panel);
ss.show(app);
}
//
function click(e){
var row=ss.getActiveRange().getRowIndex();
var app = UiApp.getActiveApplication();
var txtBox = app.getElementById("item");
var subbtn = app.getElementById("next").setText("next ?")
var txt0=app.getElementById("lab0").setText('--');
var txt1=app.getElementById("lab1").setText('no match').setStyleAttribute("background", "white");// default value to start with
var txt2=app.getElementById("lab2").setText('');
var item=e.parameter.item.toLowerCase(); // item to search for
var hidden=app.getElementById("hidden")
var data = sh.getRange(2,1,lastrow,8).getValues();// get the 8 columns of data
for(nn=0;nn<data.length;++nn){ ;// iterate trough
if(data[nn].toString().toLowerCase().match(item.toString())==item.toString()&&item!=''){;// if a match is found in one of the 3 fields, break the loop and show results
var datarow=data[nn]
for(cc=0;cc<datarow.length;++cc){
if(datarow[cc].toString().toLowerCase().match(item.toString())==item.toString()&&item!=''){break}
}
var idx=cc
txt0.setText(nn+2);
txt1.setText(data[nn][idx]).setStyleAttribute("background", "cyan");
txt2.setText(data[nn][idx+1]);
sh.getRange(nn+2,idx+1).activate();
subbtn.setText("found '"+item+"' in row "+Number(nn+2)+", next ?");
hidden.setValue(nn.toString())
break
}
}
return app ;// update UI
}
function next(e){
var row=ss.getActiveRange().getRowIndex();
var app = UiApp.getActiveApplication();
var txtBox = app.getElementById("item");
var subbtn = app.getElementById("next").setText("no other match")
var hidden=app.getElementById("hidden");
var start=Number(e.parameter.hidden)+1;//returns the last search index stored in the UI
var item=e.parameter.item.toLowerCase(); // item to search for
var txt0=app.getElementById("lab0");
var txt1=app.getElementById("lab1").setStyleAttribute("background", "yellow");
var txt2=app.getElementById("lab2");
var data = sh.getRange(2,1,lastrow,8).getValues();// get the 3 columns of data
for(nn=start;nn<data.length;++nn){ ;// iterate trough
if(data[nn].toString().toLowerCase().match(item.toString())==item.toString()&&item!=''){;// if a match is found in one of the 3 fields, break the loop and show results
var datarow=data[nn]
for(cc=0;cc<datarow.length;++cc){
if(datarow[cc].toString().toLowerCase().match(item.toString())==item.toString()&&item!=''){break}
}
var idx=cc
txt0.setText(nn+2);
txt1.setText(data[nn][idx]).setStyleAttribute("background", "cyan");
txt2.setText(data[nn][idx+1]);
sh.getRange(nn+2,idx+1).activate();
subbtn.setText("found '"+item+"' in row "+Number(nn+2)+", next ?");
hidden.setValue(nn.toString())
break
}
}
return app ;// update UI
}
//
function gendoclisttest(){
sh.getRange(1,1).setValue('.');// usefull to allow for 'clear' if page is empty
sh.getRange(1,1,ss.getLastRow(),ss.getLastColumn()).clear().setWrap(false).setBorder(false,false,false,false,false,false);// clears whole sheet
var doclist=new Array();
var folders=DocsList.getFolders()
for(ff=0;ff<folders.length;++ff){
doclist=folders[ff].getFiles(0,2000)
var names = new Array();
for (nn=0;nn<doclist.length;++nn){
names.push([doclist[nn].getName(),doclist[nn].getId()]);
}
if (names.length>0){
names.sort();
var row=ss.getLastRow()+1;
sh.getRange(row,1,1,3).setValues([["Folders","Generic Doc Names","ID"]]).setBorder(false,true,true,true,true,true).setBackgroundColor("#dddddd");
sh.getRange(row+1,1).setValue(folders[ff].getName())
sh.getRange(row+1,2,names.length,2).setValues(names);
}
}
doclist=DocsList.getRootFolder().getFiles(0,2000)
var names = new Array();
for (nn=0;nn<doclist.length;++nn){
names.push([doclist[nn].getName(),doclist[nn].getId()]);
}
if (names.length>0){
names.sort();
var row=ss.getLastRow()+1;
sh.getRange(row,1,1,3).setValues([["Root","Generic Doc Names","ID"]]).setBorder(false,true,true,true,true,true).setBackgroundColor("#dddddd");
sh.getRange(row+1,2,names.length,2).setValues(names);
}
}
//
function doclistcat(){
var doclist=new Array();
var folders=DocsList.getFolders()
var zz=0;var nn=0
for(ff=0;ff<folders.length;++ff){
doclist=folders[ff].getFilesByType("spreadsheet",0,2000);
var names = new Array();
for (nn=0;nn<doclist.length;++nn){
names.push([doclist[nn].getName(),doclist[nn].getId()]);
}
if(names.length>0){
names.sort();
zz=zz+nn
var row=zz-nn+1
sh.getRange(row,4,1,3).setValues([["Folders","Spreadsheet Names","ID"]]).setBorder(true,true,true,true,true,true).setBackgroundColor("#dddddd");
sh.getRange(row+1,4).setValue(folders[ff].getName()).setB
sh.getRange(row+1,5,names.length,2).setValues(names);
}
}
doclist=DocsList.getRootFolder().getFilesByType("spreadsheet",0,2000);
var names = new Array();
for (nn=0;nn<doclist.length;++nn){
names.push([doclist[nn].getName(),doclist[nn].getId()]);
}
if(names.length>0){
names.sort();
zz=zz+nn
var row=zz-nn+1
sh.getRange(row,4,1,3).setValues([["Root","Spreadsheet Names","ID"]]).setBorder(true,true,true,true,true,true).setBackgroundColor("#dddddd");
sh.getRange(row+1,5,names.length,2).setValues(names);
}
//
var zz=0;var nn=0
for(ff=0;ff<folders.length;++ff){
doclist=folders[ff].getFilesByType("document",0,2000);
var names = new Array();
for (nn=0;nn<doclist.length;++nn){
names.push([doclist[nn].getName(),doclist[nn].getId()]);
}
if(names.length>0){
names.sort();
zz=zz+nn
var row=zz-nn+1
sh.getRange(row,7,1,3).setValues([["Folders","Text Document Names","ID"]]).setBorder(true,true,true,true,true,true).setBackgroundColor("#dddddd");
sh.getRange(row+1,7).setValue(folders[ff].getName()).setB
sh.getRange(row+1,8,names.length,2).setValues(names);
}
}
doclist=DocsList.getRootFolder().getFilesByType("document",0,2000);
var names = new Array();
for (nn=0;nn<doclist.length;++nn){
names.push([doclist[nn].getName(),doclist[nn].getId()]);
}
if(names.length>0){
names.sort();
zz=zz+nn
var row=zz-nn+1
sh.getRange(row,7,1,3).setValues([["Root","document Names","ID"]]).setBorder(true,true,true,true,true,true).setBackgroundColor("#dddddd");
sh.getRange(row+1,8,names.length,2).setValues(names);
}
}
//
//eof

Resources