I'm trying to retrieve the customers name by alert based on the account number that's entered into the textbox by i'm having trouble referencing the textbox (>>txtFree<<). I just not sure what i must replace it with if anyone could help please.
HTML
Account Number: <input type="text" id="txtFreeBank" name="txtFreeBank" />
JS
function checkBankAc() {
var txtFree = parseFloat(document.getElementById('txtFreeBank').value);
var bankdetails = Parse.Object.extend("BankDetails");
var query = new Parse.Query(bankdetails);
query.equalTo("AccountNum", >>txtFree<<);
query.find({
success: function (results) {
alert("Successfully retrieved " + results.length + " scores.");
for (var i = 0; i < results.length; i++) {
var object = results[i];
alert(object.id + ' - ' + object.get('CustomerName'));
}
},
error: function (error) {
alert("Error: " + error.code + " " + error.message);
}
});
}
You will be able to access the data entered switching your >>txtFree<< for the following:
document.getElementById('txtFreeBank').value
Related
I picked up the following JavaScript I'm a novice on JS. Anyway I want to achieve if emailsignature isdefault not equals 0 then add the handler email signature, below is the code, how do I do this?, where would I insert this IF condition?
//find the users signature dynamically
var query = "?$select=title,safehtml&$filter=ownerid/ownerid eq " + signatureUserId;
Xrm.WebApi.retrieveMultipleRecords("emailsignature", query).then(
function success(result) {
//The below for each goes through all the email signatures and it looks like the code is grabbing the first signature on the list. How do I code a filter to add default?
// I want to only add the isdefault signature to the email, i.e. if signarure not equal to NO add.
for (var i = 0; i < result.entities.length; i++) { //This is itterating through all the signature
var emailSig = result.entities[0];
if (emailSig != null) {
if (emailDescription === "<p></p>" || emailSubject === null )
{
var signatureDynamic = emailSig["safehtml"];
formContext.getAttribute("description").setValue("<br /><br />" + signatureDynamic);
}
else if (emailSubject .includes("RE:"))
{
var signatureDynamic = emailSig["safehtml"];
formContext.getAttribute("description").setValue("<br /><br />" + signatureDynamic + emailDescription);
}
}
break;
}
},
function (error) {
alert("Error: " + error.message);
});
//end users signature
}
break; // We will grab the first one
}
},
function (error) {
alert("Error: " + error.message);
});
}
I have succesfuly stored some geopoints in Parse.com and now in another page i want to console log them all so i can place them into some variables and then put one marker in google map.
So i'm trying with this code to get them but for sure i miss some thing and i need your advice.
Parse.initialize("APPID", "JSKEY");
var PhotoObject = Parse.Object.extend('magazia');
var photoObject = new PhotoObject();
var query = new Parse.Query(PhotoObject);
query.select('latlon');
query.find({
success: function(locationList) {
alert("Successfully retrieved " + locationList.length + " locations.");
for (var i = 0; i < locationList.length; i++) {
var locationsBlock = {};
locationsBlock = JSON.parse(JSON.stringify(locationList[i]));
var location = {};
location = JSON.parse(JSON.stringify(locationsBlock.geolocation));
alert(location.latitude);
};
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
So i have a class called "magazia"
and inside that class there is a column which is called "latlon" and its a Geopoint. The content of this column is for example 48.29124, 28.52015 float number.
The alert shows me the correct number of rows that there are in the "magazia" class.
Does anyone knows why i dont get the results from my code above?
thanks in advance.
Ok that was a stupid mistake
var PhotoObject = Parse.Object.extend('magazia');
var photoObject = new PhotoObject();
var query = new Parse.Query(PhotoObject);
query.select('latlon');
query.find({
success: function(locationList) {
console.log("Successfully retrieved " + locationList.length + " locations.");
for (var i = 0; i < locationList.length; i++) {
var locationsBlock = {};
locationsBlock = JSON.parse(JSON.stringify(locationList[1]));
var location = {};
location = JSON.parse(JSON.stringify(locationsBlock.latlon));
var lat = location.latitude;
var lon = location.longitude;
console.log(lat, lon);
};
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
instead of locationsBlock.geolocation
there should be locationsBlock.latlon
I have a JavaScript table getting parse data need to use the objectid of each row for a later date need to store them in variable or something like that
Can any help me.
Cheers
UPDATE 1
Here is some code to help
var firstTeamResults = Parse.Object.extend(strUser);
var query = new Parse.Query(firstTeamResults);
query.startsWith("NameGame", ask4);
query.descending("updateAt");
query.find(
{
success: function(results)
{
for (var i = 0; i < results.length; i++)
{
var object = results[i];
(function($) {
$("#first-team-results-table").append("<tr><td>"
+ object.get("NameGame")
+ "</td><td>"
+ object.get("item")
+ "</td><td>"
+ "<input id='video' type='submit' value='Video'/>"
+ "</td><td>"
+ object.get("des")
+ "</td><td>"
+ object.get("group")
+ "</td><td>"
+ "<input id='more' type='submit' value='More'/>"
+ "</td></tr>");
})(jQuery);
}
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
})
});
I think I understand what you're trying to ask. After you query the objects and get them, you can just call the .id method on each object to get the objectId.
See the example below.
var YourClass = Parse.Object.extend("YourClassName");
var query = new Parse.Query(YourClass);
//An unconstrained Query to get all objects in the table
query.find({
success: function(results) {
for(var i=0; i <results.length; i++){
var objectId = results[i].id //This returns you the objectId of each row
//You can do what you want with objectId now.
}
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
The Parse Docs show that you can retrieve the three special properties of every object by using the methods below.
var objectId = yourObject.id;
var updatedAt = yourObject.updatedAt;
var createdAt = yourObject.createdAt;
I have a column in my Parse database populated with numbers and I'm trying to add them all together to get a total.
I know how to do the adding together if the data returned is a single array, but I can only figure out how to return the numbers as individual objects. This is my code which does that:
var query = new Parse.Query(Services);
query.exists("costMonthly");
query.find({
success: function (results) {
for (var i = 0; i < results.length; i++) {
var object = results[i];
console.log(object.get('costMonthly'));
}
},
error: function (error) {
alert("Error: " + error.code + " " + error.message);
}
});
How would I go about fetching what I want as an array or at least converting what I have into one?
It looks like you are trying to sum the costMonthly field. You can use reduce to do this easily:
var query = new Parse.Query(Services);
query.exists("costMonthly");
query.find({
success: function (results) {
var sum = results.reduce(function(prev, cur) {
return prev + cur.get('costMonthly');
}, 0);
},
error: function (error) {
alert("Error: " + error.code + " " + error.message);
}
});
If your goal is an array of the costMonthly values, this will work:
var monthlyCosts = results.map(function(item) {
return item.get('costMonthly');
});
Read more about reduce here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
You can create a temporary array , and push results though through iteration , not the best solution , but is very useful if you want to manipulate results later :
var costMonthlyArray=[];
var query = new Parse.Query(Services);
query.exists("costMonthly");
query.find({
success: function (results) {
for (var i = 0; i < results.length; i++) {
var object = results[i];
var cost=object.get('costMonthly');
costMonthlyArray.push(cost);
console.log(cost);
}
},
error: function (error) {
alert("Error: " + error.code + " " + error.message);
}
});
The below code successfully runs a query and returns the results. However when being displayed on the page, the label for
item.username and item.imageURL
are returning as undefined or in the images case "not found).
I believe I may have to change the code which is displaying this on the page, because a recent query change is now returning multiple possibilities for username:
Before it just returned fromUser for this, now the query also can potentially return toUser. However the resulsts on the page should only show one or the other, not both.
Just stuck on what I need to adjust below to allow this?
var currentUser = Parse.User.current();
var FriendRequest = Parse.Object.extend("FriendRequest");
var queryOne = new Parse.Query(FriendRequest);
queryOne.include('fromUser');
queryOne.include("myBadge");
queryOne.equalTo("fromUser", currentUser);
var queryTwo = new Parse.Query(FriendRequest);
queryTwo.include('toUser');
queryTwo.include("myBadge");
queryTwo.equalTo("toUser", currentUser);
var mainQuery = Parse.Query.or(queryOne, queryTwo);
mainQuery.equalTo("status", "Connected");
mainQuery.find({
success: function(results) {
var friends = [];
for (var i = 0; i < results.length; i++) {
friends.push({
imageURL: results[i].get('fromUser').get('pic'),
username: results[i].get('fromUser').get('username'),
userId: results[i].get('fromUser').id,
status: results[i].get('status'),
// Saves the object so that it can be used below to change the status//
fetchedObject: results[i]
});
}
var select = document.getElementById("FriendsConnected");
$.each(friends, function(i, v) {
var opt = v.username;
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
})
$('#containerFriends').empty();
$('#containerFriendsConnected').empty();
_.each(friends, function(item) {
var wrapper = $('<div class="portfolio-item-thumb one-third"></div>');
wrapper.append('<img class="responsive-image friendImgOutline" src="' + item.imageURL + '" />'+ '<br>');
wrapper.append('<div class="tag">' + item.username + '</div>');
wrapper.append('<div type="button" class="btn btn-danger mrs decline">' + 'Unfriend' + '</div>');
$('#containerFriends').append(wrapper);
//The following lets the user accept or decline a friend request by changing the status the status from Pending to Declined/////
$(document).on('click', function() {
$(".decline").click(function() {
item.fetchedObject.set("status", "Rejected");
item.fetchedObject.save(null, {
success: function(results) {
console.log("REJECTED");
},
error: function(contact, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
alert("Error: " + error.code + " " + error.message);
}
});
});
});
});
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
The mainQuery needs to include the keys as well.
var mainQuery = Parse.Query.or(queryOne, queryTwo);
mainQuery.include("toUser"); //Add this line
mainQuery.include("fromUser"); //Add this line
mainQuery.equalTo("status", "Connected");