How do I get redirected to a record type after executing a command in a client script. Explaining better, I'm in a client script, and after clicking a button, a new record is generated in another record type, and I want to be redirected there.
Thank you
I need to leave this page after performing the procedures, and be redirected to the record I just created
var newType = <NetSuite ID of record type>;
// making new record code
var newId = newRecord.save();
// performing the procedures
// Requires the N/url module
var output = url.resolveRecord({
recordType: newType,
recordId: newId,
isEditMode: true
});
window.location.replace(output);
I need to store the email of a logged in user, which I have stored into
sessionStorage with the line of code:
sessionStorage.setItem("loggedInUser", $("#email").val());
But in a different program, I need to store the email as something so that it can be sorted and posted to a php file that inserts it into my database. Here is my javascript so far.
$(document).ready(function () {
//When the submit button on the recruitment form is pressed.
$("#SubmitRecruit").on("click", function () {
//store each individual entry into a separate variable.
var email = sessionStorage.loggedInUser;
var forename = document.getElementById("forename").value;
var surname = document.getElementById("surname").value;
var jobType = document.getElementById("jobType").value;
var phoneNo = document.getElementById("phoneNo").value;
//create an array with the details in.
var recruitdetail = {
email: email,
forename: forename,
surname: surname,
password: password,
phoneNo: phoneNo,
}
//log the forename in the console so that we know that the register has been successful.
console.log(email)
//direct the user to the login page and alert them that their registration was successful.
window.location.href = "../index.html"
alert("Your recruitment post was made, thank you. We will get back to you shortly.")
//posts the JSON object to the php file so it can fill the database, and converts the register array into JSON so it can be read.
var jqxhr = $.post("../php/recruit.php", JSON.stringify(recruitdetail)
)
}
})
On the 5th line I tried to make it equal to sessionStorage.loggedInUser with no avail. I know I need to store email as something from session surely, as then it will be passed back into php and stored in db, but I cannot figure out what or how to do this. Any help will be greatly appreciated.
In order to use local storage with our array, we'll need to convert our array into a string using a method that makes it easy for us to unconvert later. The way convert an array into a string is by using the JSON stringify function.
Let's say you have the following array called movies:
var movies = ["Reservoir Dogs", "Pulp Fiction", "Jackie Brown",
"Kill Bill", "Death Proof", "Inglourious Basterds"];
Using the stringify function, your movies array can be turned into a string by using the following syntax:
JSON.stringify(movies)
Since we want to store everything into our local storage, when you put it all together, you get the following:
var movies = ["Reservoir Dogs", "Pulp Fiction", "Jackie Brown",
"Kill Bill", "Death Proof", "Inglourious Basterds"];
localStorage.setItem("quentinTarantino", JSON.stringify(movies));
To get the item from session storage try using the getItem method:
var email = sessionStorage.getItem("loggedInUser");
See sessionStorage documentation.
For the ajax request, just pass the object directly to $.post and put the alert in the success callback so it only shows when the request completes successfully:
//posts the JSON object to the php file so it can fill the database, and converts the register array into JSON so it can be read.
var jqxhr = $.post("../php/recruit.php", recruitdetail, function(data) {
alert("Your recruitment post was made, thank you. We will get back to you shortly.")
});
As a side note - if you have a table of users/logins, the email of each user should stored in that table. The foreign key between your users table and other tables would then be an (auto-incrementing) ID, rather than an email address. This makes the system much more flexible (email can be changed, etc).
If by different program you mean different application on different domain, then you can try sending the email value through an AJAX request to be stored in the PHP session.
If on the same domain but just a different app running in a different tab, then you can use localStorage, with the same syntax as sessionStorage. Note that sessionStorage data is limited to the tab in which it was set.
localStorage.setItem("loggedInUser", $("#email").val());
and then
var email = localStorage.loggedInUser;
Or you can use cookies.
https://www.w3schools.com/js/js_cookies.asp
I have to show data belonging to a user that logged in.
My database structure is as follows:
Users/Drivers/Uid/name,phone...
How can I show the data of a user that logged in by using JavaScript as a Text?
<a> Username </a>
If you have this HTML:
<a id="username"> Username </a>
And this database structure:
Users
Drivers
Uid: { name: "Name", phone: "Phone number" }
Then you can display the name of the current user with:
var currentUser = firebase.auth().currentUser;
var userRef = firebase.database().ref("Users/Drivers").child(currentUser.uid);
userRef.on("value", function(snapshot) {
document.getElementById("username").innerText = snapshot.val().name;
})
So this code does (line by line):
Determine the current user
Create a reference to that user's data in the database
Starts listening for that data, meaning it loads the current data, and then monitors for any changes
Puts the name of the user into the element.
Line 4 will be called immediately, with the current value of the user, and then every time that user data change.
Also see the Firebase documentation on listening for values.
If the page can also be loaded when the user is not signed in (yet), you'll want to make sure to only run this code when the user did sign in. You can do this by using a so-called auth state change listener, which is called whenever the user's auth state changes:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
var userRef = firebase.database().ref("Users/Drivers").child(user.uid);
userRef.on("value", function(snapshot) {
document.getElementById("username").innerText = snapshot.val().name;
})
}
});
See the Firebase documentation on getting the current signed in user..
I'm experimenting with Firebase/javascript and am wondering how do I assign a key to a specific browser instance when created?
Upon entry, user is greeted with a user input field for their name and submit button
When the submit button is clicked the user information is sent to firebase and saved under a newly created key
I know how to do this and how to retrieve the data from firebase but,
how do i ensure the key that is created gets assigned to the specific user so that only the information in that key is sent back to the user or updated?
I am trying to do this without having a user signup or login. Is there a way to do this?
When the user clicks the submit button, you will send the name and the key to the database:
var ref = firebase.database().ref();
var reference = ref.child('users');
var post = reference.push();
post.set({
username:name
});
Then after that you will have this in the database:
users
pushkey
username: userx
another user adds his name and clicks submit:
user
pushkey <--- this key will be only to this user
username: userx
pushkey1 <--- will be only to usery
username:usery
I'm adding users manually as I don't want them to access the app without authorisation.
Upon adding a user,I would like to add a new child to the database (named from the user email) and send him an email with his logins.
So far I've arrived to this, that doesn't work (webpack) and I cannot create a child using the current user's email:
firebase.auth.user().onCreate(function(event) {
var uid = event.data.uid;
return admin.database().ref("/users/" + uid)
});
I also found this one for the email:
exports.sendWelcomeEmail = functions.auth.user().onCreate(function(event) {
var uid = event.data.uid;
return sendEmail(uid);
});
Do you have any idea what the formula looks like to create a child in the DB with the user and send him an email with his credentials right upon creation of a new user.