Safari browser not running my code properly? - javascript

I have the following class:
class Portal {
caption = "";
thumbnailURL = "";
profileImgURL = "";
mp3 = "";
timestamp = 0.0;
username = "";
uid = "";
num = 0;
// var caption = new String();
// var caption = "";
// var thumbnailURL = "";
// var profileImgURL = "";
constructor(cap, thumb, prof, mp3, timestamp, username, uid) {
this.caption = cap;
this.thumbnailURL = thumb;
this.profileImgURL = prof;
this.mp3 = mp3;
this.timestamp = timestamp;
this.username = username;
this.uid = uid;
}
}
When I run this on safari brower I get the two bellow errors.
SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list.
And then despite running the script for the portal class before the main.js script I get this:
Unhandled Promise Rejection: ReferenceError: Can't find variable: Portal
How do I fix this?

Class field declarations are not finalised, so I suppose Safari is not yet supporting them. – VLAZ 3 mins ago
All that is needed is:
class Portal {
constructor(cap, thumb, prof, mp3, timestamp, username, uid) {
this.caption = cap;
this.thumbnailURL = thumb;
this.profileImgURL = prof;
this.mp3 = mp3;
this.timestamp = timestamp;
this.username = username;
this.uid = uid;
}
}

Related

JavaScript Web Resource issue: getGrid() suddenly started failing

I have a few different JavaScript web resources that use the getGrid(), all of which started failing this week after I enabled the 2020 Wave 1 Updates in D365. The error message shows:
"Error occurred :TypeError: Unable to get property 'getGrid' of undefined or null reference"
Here is my code:
function GetTotalResourceCount(executionContext) {
console.log("function started");
var execContext = executionContext;
var formContext = executionContext.getFormContext();
var resourceyescount = 0;
try {
var gridCtx = formContext._gridControl;
var grid = gridCtx.getGrid();
var allRows = grid.getRows();
var duplicatesFound = 0;
//loop through rows and get the attribute collection
allRows.forEach(function (row, rowIndex) {
var thisRow = row.getData().entity;
var thisRowId = thisRow.getId();
var thisResource = "";
var thisResourceName = "";
var thisResourceID = "";
console.log("this row id=" + thisRowId);
var thisAttributeColl = row.getData().entity.attributes;
thisAttributeColl.forEach(function (thisAttribute, attrIndex) {
var msg = "";
if (thisAttribute.getName() == "new_resource") {
thisResource = thisAttribute.getValue();
thisResourceID = thisResource[0].id;
thisResourceName = thisResource[0].name;
console.log("this resource name=" + thisResourceName)
}
});
var allRows2 = formContext.getGrid().getRows();
//loop through rows and get the attribute collection
allRows2.forEach(function (row, rowIndex) {
var thatRow = row.getData().entity;
var thatRowId = thatRow.getId();
var thatAttributeColl = row.getData().entity.attributes;
var thatResource = "";
var thatResourceName = "";
var thatResourceID = "";
thatAttributeColl.forEach(function (thatAttribute, attrIndex) {
if (thatAttribute.getName() == "new_resource") {
thatResource = thatAttribute.getValue();
thatResourceID = thatResource[0].id;
thatResourceName = thatResource[0].name;
if (thatResourceID == thisResourceID && thatRowId != thisRowId) {
duplicatesFound++;
var msg = "Duplicate resource " + thatResource;
console.log("duplicates found= " + duplicatesFound);
}
}
});
});
});
if (duplicatesFound > 0) {
console.log("duplicate found");
Xrm.Page.getAttribute("new_showduplicateerror").setValue(true);
Xrm.Page.getControl("new_showduplicateerror").setVisible(true);
Xrm.Page.getControl("new_showduplicateerror").setNotification("A duplicate resource was found. Please remove this before saving.");
} else {
Xrm.Page.getAttribute("new_showduplicateerror").setValue(false);
Xrm.Page.getControl("new_showduplicateerror").setVisible(false);
Xrm.Page.getControl("new_showduplicateerror").clearNotification();
}
} catch (err) {
console.log('Error occurred :' + err)
}
}
Here is a separate web resource that triggers the function:
function TriggerSalesQDResourceCount(executionContext){
var formContext = executionContext.getFormContext();
formContext.getControl("s_qd").addOnLoad(GetTotalResourceCount);
}
Any ideas how I can fix this? Is this a known issue with the new D365 wave 1 update?
Thanks!
This is the problem with unsupported (undocumented) code usage, which will break in future updates.
Unsupported:
var gridCtx = formContext._gridControl;
You have to switch to these supported methods.
function doSomething(executionContext) {
var formContext = executionContext.getFormContext(); // get the form Context
var gridContext = formContext.getControl("Contacts"); // get the grid context
// Perform operations on the subgrid
var grid = gridContext.getGrid();
}
References:
Client API grid context
Grid (Client API reference)

Docusign Signer Name

At my current company we have DocuSign integrated with Salesforce for sending out contracts to our potential clients.
Each contract is required to be signed by our potential client but also from our VP of sales/services.
I created a custom button on the quote object to submit the quote to DocuSign passing the information required (Signer Role, name, email etc) The problem I am having is that for some reason the full name of the second signer (the internal signer) does not get passed on to DocuSign so the sales rep has to manually go and edit the recipients each time and add the name.
Button code:
var quoteApproved = {!Quote.Quote_Approved__c};
//********* Option Declarations (Do not modify )*********//
var RC = '';
var RSL = '';
var RSRO = '';
var RROS = '';
var CCRM = '';
var CCTM = '';
var CCNM = '';
var CRCL = '';
var CRL = '';
var OCO = '';
var DST = '';
var LA = '';
var CEM = '';
var CES = '';
var STB = '';
var SSB = '';
var SES = '';
var SEM = '';
var SRS = '';
var SCS = '';
var RES = '';
//*************************************************//
switch ("{!Quote.Signed_by__c}") {
case "John Cash":
CRL = "Email~john.cash#company.com; FirstName~John; LastName~Cash; Role~Signer 2; RoutingOrder~1";
CCTM = "Signer 2~Signer";
break;
case "Mark Cash":
CRL = "Email~mark.cash#company.com; FirstName~Mark; LastName~Cash; Role~Signer 2; RoutingOrder~1";
CCTM = "Signer 2~Signer";
}
if (quoteApproved) {
{
!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")
}
var sourceId = DSGetPageIDFromHref();
var RQD = DSGetPageIDFromHref();
window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID=" + sourceId + "&CCTM=" + CCTM + "&CRL=" + CRL + "&RQD=" + RQD;
} else {
alert("Your quote has not been approved yet. \nPlease submit for approval before sending the contract.");
}
I have resolved the issue. The RQD variable was adding a # at the end of the URL preventing the completion of the field mapping.

Uncaught TypeError: Cannot read property 'toString' of undefined JavaScript

I have the following function in my JavaScript code and when I run it shows me the following error Cannot read property 'toString' of undefined I am developing an SharePoint web application.
function startTest(quizID) {
currentQuizItem = quizList.getItemById(quizID);
var quizName;
context.load(currentQuizItem);
var userName = user.get_title();
var audiencenames = currentQuizItem.get_fieldValues()["Audienca"];
var straudience = audiencenames.toString();
straudience = straudience.toUpperCase();
straudience = straudience.replace(/\s/g, '');
userName = userName.toUpperCase();
userName = userName.replace(/\s/g, '');
var rezultati = straudience.match(userName);
alert(rezultati);
}
please help me!
context.executeQueryAsync() is what my code was missing. I Added it and it worked.
function startTest(quizID) {
currentQuizItem = quizList.getItemById(quizID);
var quizName;
context.load(currentQuizItem);
var userName = user.get_title();
context.executeQueryAsync(function() {
var audiencenames = currentQuizItem.get_fieldValues()["Audienca"];
var straudience = audiencenames.toString();
straudience = straudience.toUpperCase();
straudience = straudience.replace(/\s/g, '');
userName = userName.toUpperCase();
userName = userName.replace(/\s/g, '');
var rezultati = straudience.match(userName);
alert(rezultati);
},
function() {
// handle error
});
}

IndexedBD and localStorage undefined error

I have an indexedDB which im trying to use to capture form information on user registration. That part is working fine but the prof wants an account to be create once with the username and password set on creation so he can log in.
The way I approached this was with a localStorage API. I created a function to check if the admin account had ever been created, and if not to create it calling the addAdmin() function.
I tried to create addAdmin() by copying my addObject() but for some reason my db variable is returning as undefined in the console.
Error" Uncaught TypeError: Cannot call method 'transaction' of undefined
var mainForm, fName, lName, uName, pass, email, dob, phone, bio, nl, terms, school, gender, save, reset, db;
//-------------USER DB------------------//
function startDB(){
mainForm = document.getElementById('mainFormSidebar');
fname = document.getElementById('fName');
lName = document.getElementById('lName');
users = document.getElementById('uName');
pass = document.getElementById('password');
email = document.getElementById('email');
dob = document.getElementById('dob');
phone = document.getElementById('phone');
bio = document.getElementById('bio');
nl = document.getElementById('newsletter');
terms = document.getElementById('terms');
school = document.getElementById('school');
gender = document.getElementsByName('gender');
save = document.getElementById('save');
reset = document.getElementById('reset');
reset.addEventListener('click',clearForm);
databox = document.getElementById('databox');
mainForm.addEventListener('submit',addObject);
//open DB
var request = indexedDB.open('macroPlay');
//if fails
request.addEventListener('error', showerror);
//if succeeds
request.addEventListener('success', start);
//if !exist, create.
request.addEventListener('upgradeneeded', createdb);
//Create Admin account on launch
chkAdmin();
}
function createdb(e){
var datababase = e.target.result;
var myusers = datababase.createObjectStore('users', {keyPath: 'userName'});
}
function start(e){
db = e.target.result;
showUsers();// Show all values in the object store
}
function addObject(){
if(confirm('Are you sure you want to resgister?')){
var fName = document.getElementById('fName').value;
var lName = document.getElementById('lName').value;
var userName = document.getElementById('uName').value;
var pass = document.getElementById('password').value;
var email = document.getElementById('email').value;
var dob = document.getElementById('dob').value;
var phone = document.getElementById('phone').value;
var bio = document.getElementById('bio').value;
var nl = document.getElementById('nl').value;
var terms = document.getElementById('terms').value;
var school = document.getElementById('school').value;
//May need to set a loop to find value of radio
var gender;
var radios = document.getElementsByName('gender');
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
gender=radios[i].value;
}
}
//set up transaction
var mytransaction = db.transaction(['users'], "readwrite");
//get object store
var myusers = mytransaction.objectStore('users');
//Add item
var request = myusers.add(new getUser(userName,fName,lName,pass,email,dob,phone,bio,nl,terms,school,gender));
}
// Show all results.
mytransaction.addEventListener('complete', showUsers);
//Reset Form Fields
resetForm();
}
function getUser(userName, fn, ln, pw, em, dob, tel, bio, nl,tm, scl, gender){
this.userName = userName;
this.fn = fn;
this.ln = ln;
this.pw = pw;
this.em = em;
this.dob = dob;
this.tel = tel;
this.bio = bio;
this.nl = nl;
this.tm = tm;
this.scl = scl;
this.gender = gender;
}
//------Create Admin Account-----//
function chkAdmin(){
alert('before adding admin');
if(localStorage.getItem('admin')!="added"){
alert('adding admin');
addAdmin();
alert('admin added');
}
}
function addAdmin(){
//set up transaction
var mytransaction = db.transaction(['users'], "readwrite");
//get object store
var myusers = mytransaction.objectStore('users');
var request = myusers.add(new getUser('admin','Shawn','Smith-Choa','admin'));
request.addEventListener('success',showUsers);
//Locally store that admin as been created
var admin = 'admin';
var value = 'added';
newItem(admin,value);
}
//-------------Web Storage API------------//
function newItem(id,style){
localStorage.setItem(id,style);
}
You're not assigning the value of db to anything so it's always undefined. I think you mean to be doing it in the createdb method, but really you should be capturing/assigning it in the start method which the success handler will trigger (I also can't find the start method anywhere)

Spoofing an IP using a node.js server?

I am coding a proxy for Minecraft servers, and would like to be able to forward the original user's IP address. The issue is, through the 'proxy', the proxy's IP is seen. I know this is the idea behind proxies, but I would like to keep the original sender's IP, and forward them to another IP.
My current code;
var net = require('net');
var sourceport = 25555;
var destport = 25565;
function bufferTrim(buf, trm){
var len = buf.length;
return buf.slice(0, len-trm);
}
net.createServer(function(s)
{
var buff = "";
var connected = false;
var cli = net.createConnection(destport);
s.on('data', function(d) {
var hex = d.toString('hex').substr(0,2);
if (connected)
{
if (hex == "fe")
{
var sName = "Faker";
var sMaxSlots = "8";
var sUsedSlots = "0";
s.write(bufferTrim(new Buffer(String.fromCharCode(0xFF).concat(String.fromCharCode(sName.length + sMaxSlots.length + sUsedSlots.length + 2)).concat(sName).concat(String.fromCharCode(0xA7)).concat(sUsedSlots).concat(String.fromCharCode(0xA7)).concat(sMaxSlots), 'ucs2'), 1));
} else {
cli.write(d);
}
} else {
buff += d.toString();
}
});
cli.on('connect', function() {
connected = true;
cli.write(buff);
});
cli.pipe(s);
}).listen(sourceport);

Categories

Resources