First of all, I'm a complete JS novice. I'm experimenting with Meteor.My objective is to to build a simple form that inserts records into a table. I've set up variables to grab values from each input, and I've placed those variables into an insert method. When I click the button, it recognizes the click, but doesn't pull any values from the inputs. I'm sure I'm missing something simple here, I just can't figure out what it is.
Here's the JS:
var Leads = new Meteor.Collection("Leads");
if (Meteor.is_client) {
Template.Leads.LeadsArr = function(){
return Leads.find();
};
Template.AddLeads.events = {
"click input.submit" : function () {
var name = document.getElementById('input#name').value();
var email = document.getElementById('#email').value();
var type = document.getElementById('#type').value();
var date = document.getElementById('#date').value();
var message = document.getElementById('#message').value();
Leads.insert({leadName : name, leadEmail : email, leadType : type, leadDate : date, leadComment : message});
}
};
} // end is_client
document.getElementById expect the id, not the selector. Also, value is a property of an input, not a function. So your input queries should be like this.
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var type = document.getElementById('type').value;
var date = document.getElementById('date').value;
var message = document.getElementById('message').value;
Related
I am passing following parameter to a form
var parameters = {};
//Set the Parent Customer field value to “Contoso”.
parameters["regardingobjectid"] = orderID;
parameters["regardingobjectidname"] = formContext.getAttribute("name").getValue();
parameters["regardingobjectidentitytype"] = "salesorder";
// Define the entity name to open the form
var entityFormOptions = {};
entityFormOptions["entityName"] = "email";
entityFormOptions["formId"] = "GUID";
// Open the form
Xrm.Navigation.openForm(entityFormOptions, parameters).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
However, following line of codes doesn't work as it sets the entity type to default one which account instead of Sales Order
parameters["regardingobjectid"] = orderID;
parameters["regardingobjectidname"] = formContext.getAttribute("name").getValue();
parameters["regardingobjectidentitytype"] = "salesorder";
What will be the parameter I need to set for the Entity Type here?
Try this instead. It should be regardingobjectidtype and not regardingobjectidentitytype. This will setup the “regarding” lookup as sales order record in opened email form. Read more
parameters["regardingobjectidtype"] = "salesorder"; // Table name.
I'm using Google Apps Script to write values from a form to a Google Spreadsheet.
I have the form in my HTML page and its action calls the Google Apps Script to write in the sheet.
Now I'd like to go back to my site with a flag var and show a message (Error or Complete) based on the result of the function.
I know how to create and set the flag variable but I don't know how to "send" it to my page. I was only able to show my flag with something like this (that's the whole function I have in GAS)
function doPost(e){
var id = "";
var name = e.parameter['name'];
var surname = e.parameter['surname'];
var serial = e.parameter['serial'];
var eMail = e.parameter['email'];
var text = e.parameter['text'];
var date = new Date();
var ans = ""
var ctrl= "WIP";
var vals = [id, date, name, surname, serial, eMail, text, ans, flag];
var sheetObj =SpreadsheetApp.openById("myKey").getSheetByName('Requests').appendRow(vals);
return ContentService.createTextOutput(someOutput);
}
Someone knows how to do what I need?
Thanks a lot for your help!
S.
You can do something like this
return ContentService.createTextOutput("Complete").setMimeType(ContentService.MimeType.TEXT);
Or in case of exception return 'Error' from your catch block like this
return ContentService.createTextOutput("Error").setMimeType(ContentService.MimeType.TEXT);
I created a form using UI Page and am trying to have some fields autopopulated onChange. I have a client script that works for the most part, but the issue arises when certain fields need to be dot-walked in order to be autopopulated. I've read that dot-walking will not work in client scripts for scoped applications and that a GlideAjax code will need to be used instead. I'm not familiar with GlideAjax and Script Includes, can someone help me with transitioning my code?
My current client script looks like this:
function beneficiary_1(){
var usr = g_user.userID;
var related = $('family_member_1').value;
var rec = new GlideRecord('hr_beneficiary');
rec.addQuery('employee',usr);
rec.addQuery('sys_id',related);
rec.query(dataReturned);
}
function dataReturned(rec){
//autopopulate the beneficiary fields pending on the user selection
if(rec.next()) {
$('fm1_ssn').value = rec.ssn;
$('fm1_address').value = rec.beneficiary_contact.address;
$('fm1_email').value = rec.beneficiary_contact.email;
$('fm1_phone').value = rec.beneficiary_contact.mobile_phone;
var dob = rec.date_of_birth;
var arr = dob.split("-");
var date = arr[1] + "/"+ arr[2] + "/" + arr[0] ;
$('fm1_date_of_birth').value = date;
}
}
fm1_address, fm1_email, and fm1_phone do not auto populate because the value is dot walking from the HR_Beneficiary table to the HR_Emergency_Contact table.
How can I transform the above code to GlideAjax format?
I haven't tested this code so you may need to debug it, but hopefully gets you on the right track. However there are a couple of steps for this.
Create a script include that pull the data and send a response to an ajax call.
Call this script include from a client script using GlideAjax.
Handle the AJAX response and populate the form.
This is part of the client script in #2
A couple of good websites to look at for this
GlideAjax documentation for reference
Returning multiple values with GlideAjax
1. Script Include - Here you will create your method to pull the data and respond to an ajax call.
This script include object has the following details
Name: BeneficiaryContact
Parateters:
sysparm_my_userid - user ID of the employee
sysparm_my_relativeid - relative sys_id
Make certain to check "Client callable" in the script include options.
var BeneficiaryContact = Class.create();
BeneficiaryContact.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getContact : function() {
// parameters
var userID = this.getParameter('sysparm_my_userid');
var relativeID = this.getParameter('sysparm_my_relativeid');
// query
var rec = new GlideRecord('hr_beneficiary');
rec.addQuery('employee', userID);
rec.addQuery('sys_id', relativeID);
rec.query();
// build object
var obj = {};
obj.has_value = rec.hasNext(); // set if a record was found
// populate object
if(rec.next()) {
obj.ssn = rec.ssn;
obj.date_of_birth = rec.date_of_birth.toString();
obj.address = rec.beneficiary_contact.address.toString();
obj.email = rec.beneficiary_contact.email.toString();
obj.mobile_phone = rec.beneficiary_contact.mobile_phone.toString();
}
// encode to json
var json = new JSON();
var data = json.encode(obj);
return data;
},
type : "BeneficiaryContact"
});
2. Client Script - Here you will call BeneficiaryContact from #1 with a client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var usr = g_user.userID;
var related = $('family_member_1').value;
var ga = new GlideAjax('BeneficiaryContact'); // call the object
ga.addParam('sysparm_name', 'getContact'); // call the function
ga.addParam('sysparm_my_userid', usr); // pass in userID
ga.addParam('sysparm_my_relativeid', related); // pass in relative sys_id
ga.getXML(populateBeneficiary);
}
3. Handle AJAX response - Deal with the response from #2
This is part of your client script
Here I put in the answer.has_value check as an example, but you may want to remove that until this works and you're done debugging.
function populateBeneficiary(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON(); // convert json in to an object
// check if a value was found
if (answer.has_value) {
var dob = answer.date_of_birth;
var arr = dob.split("-");
var date = arr[1] + "/"+ arr[2] + "/" + arr[0];
$('fm1_ssn').value = answer.ssn;
$('fm1_address').value = answer.address;
$('fm1_email').value = answer.email;
$('fm1_phone').value = answer.mobile_phone;
$('fm1_date_of_birth').value = date;
}
else {
g_form.addErrorMessage('A beneficiary was not found.');
}
}
I am getting an alert saying [object] object when I execute showlogsf function
var fdata = {fidval, fweightval, feggslaidval, fgraineatenval, fwaterval};
var fidval = document.getElementById('#fid');
var fweightval = document.getElementById('#fweight');
var feggslaidval = document.getElementById('#feggslaid');
var fgraineatenval = document.getElementById('#fgraineaten');
var fwaterval = document.getElementById('#fwater');
These are the two functions that could be triggered from button click
$('#submitf').click(function (){
localStorage.setItem ("fdatak", JSON.stringify(fdata));
});
$('#showlogsf').click(function(){
var fdataload = JSON.parse(localStorage.getItem("fdatak"));
alert(fdataload);
});
});
You're pushing an object as an alert. the HTML displays this as [object Object]. You have to address the actual properties of this object, so:
$('#showlogsf').click(function(){
var fdataload = JSON.parse(localStorage.getItem("fdatak"));
alert(fdataload.fidval);
alert(fdataload.fweightval);
alert(fdataload.feggslaidval);
// etc etc...
});
EDIT: Seems like you're also saving the document element, rather than the value. I assume the fdataload.properties are actual values, you should either grab the raw HTML data or input value of this instead of the HTML element itself
I guess your fdata is an array right?.
Try this var fdata = [fidval, fweightval, feggslaidval, fgraineatenval, fwaterval];
I edited values of array as xxx.value instead of xxx
var fdata = new Array();
$('#submitf').click(function (){
var fidval = document.getElementById('fid');
var fweightval = document.getElementById('fweight');
var feggslaidval = document.getElementById('feggslaid');
var fgraineatenval = document.getElementById('fgraineaten');
var fwaterval = document.getElementById('fwater');
var fdata = [];
like this
fdata.push (fidval.value, fweightval.value, feggslaidval.value, fgraineatenval.value, fwaterval.value);
localStorage.setItem ("fdata", JSON.stringify(fdata));
});
$('#showlogsf').click(function(){
var fdataload = JSON.parse(localStorage.getItem('fdata'));
document.getElementById("flogview").innerHTML = fdataload;
});
Now it saves but I have another problem, why it is replacing data every time I click showlogsf button??
Can you please take a look at This Demo and let me know what I am doing wrong in this Custom Function to validate the Text input?
$(function () {
var fname = $('#fname').val();
var lname = $('#lname').val();
var proceed = true;
function nameInput(inputData) {
var textBox = $.trim($(inputData).val())
if (textBox == "") {
alert('Field Can Not be Empty');
}
}
$("#pro").on("click", function (e) {
nameInput(fname);
e.preventDefault();
});
});
apparently the nameInput() is returning Field Can Not be Empty in both empty and filled format of the fname input. Thanks
You need to remove the two calls to val() when you declare your field variables:
var fname = $('#fname');
var lname = $('#lname');
As it is, you're passing the value to your method, and then in your method calling val() again.