Javascript clock in
Struggling just a big here. So I made a javascript codepage for clock in/out, but when I am trying to pass certain parameters in the clock in section of the code it will only let me pass them as a text, although, they are date/time fields or related record fields. Could someone assist me in the formatting here?
Code Page:
function showModalMessage(message, title, url) {
$('#modalmessage').empty();
$('#modaltitle').empty();
if (title === undefined || title === null) {
title = 'Alert!';
}
$('#modaltitle').append(title);
$('#modalmessage').append('<p>' + message + '</p>');
$('#mymodal').modal('show');
$('#closediv').click(function() {
window.location.href = url;
});
}
function closeModalMessage() {
$('#mymodal').modal('hide');
}
var fieldValue = function(field) {
return $(field[0]).text();
};
$.when(
$.getScript('?a=dbpage&pageid=13')
).done(function() {
$.quickbase.api('API_DoQuery', {
dbid: dbids._DBID_TIME_ENTRIES,
query: '{171.EX.1}AND{172.EX.1}',
clist: '3.174',
slist: '3',
fmt: 'structured',
promise: true
}).then(function(data) {
if ($('errcode', data).text() === '0') {
if ($('record', data).length > 1) {
window.location.href = URLRoot + dbids._DBID_TIME_ENTRIES + '?a=q&qid=83';
} else if ($('record', data).length === 1) {
let rid = fieldValue($('f[id=3]', $('record', data)[0]));
let curTime = fieldValue($('f[id=174]', $('record', data)[0]));
//console.log(rid);
//console.log(curTime);
$.quickbase.api('API_ImportFromCSV', {
dbid: dbids._DBID_TIME_ENTRIES,
records_csv: rid + ',' + curTime,
clist: '3.15',
promise: true
}).then(function(data) {
if ($('errcode', data).text() === '0') {
$('#mymodal').modal('show');
//sorryDialog('You have successfully clocked out at ' + curTime, 'Clocked Out', URLRoot + appID);
showModalMessage('You have successfully clocked out at ' + curTime, 'Clocked Out', URLRoot + appID)
} else {
showModalMessage('There was an error trying to process your request: <BR>' + $('errdetail', data).text(), 'Error', URLRoot + appID);
}
});
} else {
//sorryDialog('You have successfully clocked in', 'Clocked In', URLRoot + dbids._DBID_TIME_ENTRIES + '?a=API_AddRecord&apptoken=' + token + '&rdr=' + URLRoot + appID);
$.quickbase.api('API_AddRecord', {
dbid: dbids._DBID_TIME_ENTRIES,
field: [
{
fid: 25,
value: 'Work'
},
{
fid: 16,
value: 'In' // This will set FID 7 to the current date/time value
},
{
fid: 125,
value: '1'
},
{
fid: 13,
value: rid.toString()
}
],
promise: true
}).then(function(data) {
if ($('errcode', data).text() === '0') {
showModalMessage('You have successfully clocked in', 'Clocked In', URLRoot + appID)
} else {
showModalMessage('There was an error trying to process your request: <BR>' + $('errdetail', data).text(), 'Error', URLRoot + appID)
}
});
//showModalMessage('You have successfully clocked in', 'Clocked In', URLRoot + dbids._DBID_TIME_ENTRIES + '?a=API_AddRecord&apptoken=' + token + '&rdr=' + URLRoot + appID)
}
} else {
console.log($('errdetail', data).text(), 'Data Retrieval Error', 'false');
}
});
Issue Area:
});
------------------------------
William Hunter
------------------------------