I have an issue where we have the Trello API adding a new card to a defined list, and it is successfully adding to the list, however we are trying to use the .done to close the current window and open a hard-coded trello board. This code is used to take a record from CRM and copy the code to Trello.
var creatingtheCard = function () {
var record = getRecord(getParameterByName("id"))
if (record.Description == null) {
record.Description = "";
}
var options = document.getElementById("ListNameItem");
var listId = options[options.selectedIndex].value
Trello.post("cards", { name: record.Title, desc: record.Description + " - " + record.CustomerId.Name, idList: listId})
.done(closeWinOpenTrello)
.error(failure);
}
function closeWinOpenTrello() {
window.open("http://trello.com/b/8QWBDiTI")
window.close()
}
This function is called and it successfully creates the new card in Trello, but it wont perform the closeWinOpenTrello function, but it will perform the .error.
Also i ran this in the debugger and when i run the code step by step it will give the error and then close the window and open a new window with Trello.
Thanks in advance
Update 1
This is the failure function
var failure = function (error) {
alert(error.statusText);
}
You need to cancel the form submission. Otherwise the page changing will cause the cancelled state of the request - the browser isn't going to bother waiting for the response after the page changes, because there's no longer anything waiting on the response.
In order to do this, just return false from the onsubmit handler.
Related
I want to scrape a website which uses LightStreamer for showing live data. How can i add an event handler to receive those messages in Javascript?
Unfortunately, LightStreamer doesn't have enough tutorial.
Following sample works for me:
var myEH = function ff(msg) {
console.log("message receieved.");
};
App.ls.getSubscriptions()[0].addListener({ onItemUpdate : myEH})
When i repalce "message receieved." with msg variable, i see a non-sense array which is not similar to what i see in Chrome DevTools (Network tab> ws section).
Also, there are isActive() and isSubscribed() method for each subscription. When i check them against array elements returned by getSubscriptions(), i see that all of them are true. But, in fact, Chrome DevTools shows that only one them that is active and receives message. Finding active subscription is another problem.
Update: Thanks #Robert for his help. Finally, i could understand that getSubscriptions()[6] includes what i need. Other subscriptions update clock or other things in page. I extracted items and fields from this subscription as following:
var myItems = App.ls.getSubscriptions()[6].getItems();
var myFields = App.ls.getSubscriptions()[6].getFields();
var myEH3 = function ff(msg) {
console.log('tttt3');
};
var mySub = new Subscription("MERGE", myItems, myFields);
mySub.addListener(myEH3);
App.ls.subscribe(mySub);
But this doesn't work. Server returns error 'Data Adapter Not found.' Changing to 'mySub.addListener({ onItemUpdate: myEH3});' does not help. I have already tried to add eventhandler directly to getSubscriptions()[6] via 'App.ls.getSubscriptions()[6].addListener({ onItemUpdate : myEH3});', but my function never called. Any Hint would be greatly apprecieated.
They have tutorial, and solid api documentation...
from
<script>
require(["LightstreamerClient", "Subscription", "StaticGrid"], function(LightstreamerClient, Subscription, StaticGrid) {
var client = new LightstreamerClient(null, "HELLOWORLD");
client.connect();
// you have to create your own SubscriptionListener
var grid = new StaticGrid("hellogrid", true);
var subscription = new Subscription("MERGE", grid.extractItemList(), grid.extractFieldList());
subscription.addListener(grid);
client.subscribe(subscription);
});
</script>
Now you have to create your own subscription listener according to follow interface. And then you have onItemUpdate on your subscription listener.
Finally, I could get my head around this library. Searching JavaScript files of webpage, I found that somewhere DataAdapter will be set to subscriptions.
This is my final code:
var myItems = App.ls.getSubscriptions()[6].getItems();
var myFields = App.ls.getSubscriptions()[6].getFields();
var adaptername = App.ls.getSubscriptions()[6].getDataAdapter();
var myEH3 = function ff(msg) {
console.log('message received.');
};
var mySub = new Subscription("MERGE", myItems, myFields);
mySub.setDataAdapter(adaptername);
mySub.setRequestedSnapshot("yes");
mySub.addListener({onItemUpdate: myEH3});
App.ls.subscribe(mySub);
I have written firebase cloud function to trigger on update record. sometimes I am not getting the same record which is updating. I am adding my code below.Please check attached image also.
exports.onNotificationUpdate = functions.database.ref('/Notification/{userId}/{notificationId}/userResponse').onUpdate(event => {
return admin.database().ref(`/Notification/${event.params.userId}/${event.params.notificationId}`).once('value').then(function (snapshot) {
var notification = snapshot.val();
if (!notification) {
console.error("Notification not found on notification update");
return;
};
I can also get Notification object from the parent but I want to know issue best approach and the problem with this code.
this is error log
this is database structure
This is my 1st post here please let me know if need more information.
Thanks
You don't have to call once within the Function since it is already returning the data at the location you are listening to, just listen to the parent node.
So you should do like:
exports.onNotificationUpdate = functions.database.ref('/Notification/{userId}/{notificationId}').onUpdate(event => {
const notification = event.data.val();
if (notification === null) {
console.error("Notification not found on notification update");
return null;
//actually this would only be called in case of deletion of the Notification
} else {
//do something with the notification data: send Android notification, send mail, write in another node of the database, etc.
//BUT return a Promise
//notification const declared above is a JavaScript object containing what is under this node (i.e. a similar structure than your database structure as shown in the image within your post.)
}
});
I would suggest that you have a look at these three videos from the Firebase team:
https://www.youtube.com/watch?v=7IkUgCLr5oA&t=517s
https://www.youtube.com/watch?v=652XeeKNHSk&t=27s
https://www.youtube.com/watch?v=d9GrysWH1Lc
Also, note that Cloud Functions have been updated and the first line of your code shall be written differently if you are using a CF version above 1.0.0. See https://firebase.google.com/docs/functions/beta-v1-diff
I am having a bit of trouble with getting values from Protractor testing and being able to reuse those values.
I have an app that creates new records from a form and then displays them back to the user. On a successful addition, the user is presented with a success alert, displaying the ID of the newly created record. "You have successfully added an entry with the ID {{newEntry.id}}".
I have a suite of tests asserting that all the fields are correctly validated etc, which all work correctly. I now want to test the Update side of things by taking the newly created record and testing if a new set of values updates correctly. Therefore I want to take that ID of the newly created record and reuse it.
I have created the variable ID at the top of my suite,
var id;
I then run all the validation tests on the form and submit a correct submission. I then check if the success message is shown and that, in this instance, the ID = 2.
describe('Add users', function() {
var endpoint = "users";
var id;
correctSubmission(endpoint, id);
function correctSubmission(endpoint, id) {
describe('Testing correct submission', function() {
it('should navigate back to the list page', function() {
expect(browser.getCurrentUrl()).toBe("list/" + endpoint);
});
it('should display a success message', function() {
expect(element(by.css('.alert-success')).isPresent()).toBeTruthy();
});
it('should get the record ID from the success message', function() {
expect(element(by.css('.add-message')).evaluate('newEntry.id')).toEqual(2);
id = element(by.css('.add-message')).evaluate('newEntry.id');
return id;
});
});
};
});
I need to basically get that ID that equals 2 and return it back to the Global ID so that I can use it across other tests. Obviously that ID is currently an unresolved promise, and I have tried to use:
protractor.promise.all(id).then(function (result) {
console.log("ID is: " + result);
});
But this only logs the string.
I am a bit lost with what to do next as I have tried all sorts, but to no avail and I am pushed for time on this project.
Many thanks if you can help this Protractor n00b.
did you try using a protractor params config attribute?
exports.config = {
params: {
myid: 'somevaluehere'
}
};
Then u can access it by
browser.params.myid
var ctrl = {};
app.controller('compFac', function($scope){
$scope.tPHots = [];
ctrl.tbcInject = function (result) {
$scope.tPHots.push({URL: result});
$scope.$apply();
};
ctrl.getFingURC= function (comURL) {
FB.api( comURL+ '/picture', function(response) {
ctrl.tbcInject(response.data.url);
});
};
ctrl.getFingID= function () {
FB.api('/5151845035415464/albums', function(response) {
for(var i = 0; i < 10; i++)
{
ctrl.getFingURC(response.data[i].id);
}
});
};
ctrl.getFingID();
)};
This is a snippet for a function to grab facebook photos from albums and allow them to be used by angular templating ($scope.tPHots). The nested calls work when I go through the webpage linearly. i.e(login > click on albums > click on photos).
However once I'm looking at the photos and the press the browsers refresh button the photos fail to be retrieved and thus cannot be displayed.
Why does this happen? Is it because of the async calls and angular? I can't figure this out.
NOTE: all other non nested async calls in the compFac controller get called.
EDIT: found new error; in regards to accessing facebook data when executing getFingId(). also i used facebooks sdk to implement the login function (fb.login())
message: "An access token is required to request this resource."
In controller, you are assigning all function to ctrl object's property. When browser page refresh, when controller call all the function you have written assign to ctrl property but initial function which is ctrl.getFingID is not called. You have to called it.
Add below code at end of controller.
ctrl.getFingID();
and do you have defined ctrl variable? If not then create it below $scope.tPHots = [];
not the most ideal solution. but refreshing logged me out. or maybe the login process was too slow. still not 100% sure what the problem was. but i just had to check if the user was logged in, if not. log the user back in then search for the photos.
In a Google Spreadsheet, I have a long script that permorms many actions in steps, like:
function MyLongScript()
{
var Results1 = Action1();
//send feedback 1
var Results2 = Action2(Results1);
//send feedback 2
var Results3 = Action3(Results2);
//send feedback 3
//end code
}
And I want to show the users a dialog box that tells them that script is running and updates each step of the scritp, like "Action1 complete", ..., "Action2 complete" and so on.
So, I have the HTML interface which contains some table rows with these steps. The question is: how do I make the dialog see that the code performed a certain step?
Right now I'm trying to start the code from the dialog after it loads:
$(function() {
google.script.run
.withSuccessHandler(MainCodeSuccess)
.withFailureHandler(MainCodeFailure)
.MyLongScript();
}
And the dialog is called with the UI and HtmlService:
function CallDialog()
{
var ui = HtmlService.createTemplateFromFile('FeedbackWindow')
.evaluate()
.setWidth(300)
.setHeight(500);
SpreadsheetApp.getUi().showModalDialog(ui, "Dialog Title");
}
What I need is either a getStatus() in the dialog scritp or a sendStatus() in the server script.
What is the best way of achieving this?
You can run multiple google.script.run calls to the server simultaneously. You can't have one server call send multiple success calls back. You could have your MyLongScript() run, save progress status somewhere, and just keep that running, then have a second google.script.run executing on a loop every certain time period. You can use a JavaScript setInterval(): window.setInterval("javascript function", milliseconds); I don't think that there is a jQuery equivalent.
So it might (roughly) look like this:
$(function() {
google.script.run
.withSuccessHandler(MainCodeSuccess)
.withFailureHandler(MainCodeFailure)
.MyLongScript();
window.setInterval("statusChecker()", milliseconds);
}
window.statusChecker = function() {
google.script.run
.withSuccessHandler(statusCheckSuccess)
.withFailureHandler(onFailure)
.StatuChecker();
};
window.statusCheckSuccess = function(returnStatus) {
if (returnStatus !== false) {
//To Do - show msg to user
document.getElementById('idMsgToUser').textContent = returnStatus;
};
};
Your MyLongScript() might need to be saving the state of the current status to a file. I'm not sure if the subsequent, and simultaneous google.script.run calls wipes out the data in a global variable. If a global variable would hold the data even with all the simultaneous server scripts running, you could save the current status to a global variable. You'd need to experiment with that, or maybe someone knows the answer to that question.