This topic is locked
[SOLVED]

 Calculate on the fly - but with strings

7/26/2019 2:39:53 PM
PHPRunner General questions
M
Melanie authorDevClub member

I am trying to calculate a string for a field on an ADD screen. I am using the example for calculating tax on the fly - but using my own fields and it isn't working. I am using autofill in that field also - so then I want that string and then want to add additional strings. This is what I have in Javascript on load event:
var ctrlcheckin = Runner.getControl(pageid, 'check_in_date');

var ctrlcheckout = Runner.getControl(pageid, 'check_out_date');

var ctrlsubject = Runner.getControl(pageid, 'Subject_line_for_email');

function func() {

ctrlsubject.setValue(ctrlsubject.getValue + (ctrlcheckin.getValue) +

(ctrlcheckout.getValue));

};

ctrlcheckin.on('keyup', func);

ctrlcheckout.on('keyup', func);

/

So autofill puts the employee name in subject_line_for_email and then I really want to add after that - 7/24/2019 - 7/31/2019 so that the field should be:
Joe Blow - 7/24/2019 - 7/26/2019.
I am thinking I am not doing the function correctly to get the string.

lefty 7/26/2019



I am trying to calculate a string for a field on an ADD screen. I am using the example for calculating tax on the fly - but using my own fields and it isn't working. I am using autofill in that field also - so then I want that string and then want to add additional strings. This is what I have in Javascript on load event:
var ctrlcheckin = Runner.getControl(pageid, 'check_in_date');

var ctrlcheckout = Runner.getControl(pageid, 'check_out_date');

var ctrlsubject = Runner.getControl(pageid, 'Subject_line_for_email');

function func() {

ctrlsubject.setValue(ctrlsubject.getValue + (ctrlcheckin.getValue) +

(ctrlcheckout.getValue));

};

ctrlcheckin.on('keyup', func);

ctrlcheckout.on('keyup', func);

/

So autofill puts the employee name in subject_line_for_email and then I really want to add after that - 7/24/2019 - 7/31/2019 so that the field should be:
Joe Blow - 7/24/2019 - 7/26/2019.
I am thinking I am not doing the function correctly to get the string.


Check This. Here And Here

M
Melanie authorDevClub member 7/26/2019



Check This. Here And Here


Thanks - changed to this, but my field still isn't getting populated when I change the date fields: I am now getting the text 'undefined' written to that field when I put a date in check in.
var ctrlcheckin = Runner.getControl(pageid, 'check_in_date');
var str_date1 = ctrlcheckin.getStringValue();

var ctrlcheckout = Runner.getControl(pageid, 'check_out_date');
var str_date2 = ctrlcheckout.getStringValue();
var ctrlsubject = Runner.getControl(pageid, 'Subject_line_for_email');

function func() {

ctrlsubject.setValue(str_date1.getValue + ' - ' + str_date2 );

};

ctrlcheckin.on('keyup', func);

ctrlcheckout.on('keyup', func);

lefty 7/26/2019



Thanks - changed to this, but my field still isn't getting populated when I change the date fields: I am now getting the text 'undefined' written to that field when I put a date in check in.
var ctrlcheckin = Runner.getControl(pageid, 'check_in_date');
var str_date1 = ctrlcheckin.getStringValue();

var ctrlcheckout = Runner.getControl(pageid, 'check_out_date');
var str_date2 = ctrlcheckout.getStringValue();
var ctrlsubject = Runner.getControl(pageid, 'Subject_line_for_email');

function func() {

ctrlsubject.setValue( );

};

ctrlcheckin.on('keyup', func);

ctrlcheckout.on('keyup', func);


oophs , the date field is not defined .
var ctrlcheck_in_date = Runner.getControl(pageid, 'check_in_date');

var ctrlcheck_out_date = Runner.getControl(pageid, 'check_out_date');

var ctrlsubject_line_for_email = Runner.getControl(pageid, 'Subject_line_for_email');

[color="#1C2837"]

function func() {

ctrlsubject.setValue(ctrlsubject_line_for_email.getValue + (ctrl_check_in_date.getValue) +

(ctl_check_out_date.getValue));

};

ctrlcheck_in_date.on('keyup', func);

ctrlcheck_out_date.on('keyup', func);

ctrlsubject_line_for_email.on('Keyup, func);
unless your field names are alias. If don't work you have to use date strings as my last post.
See "Doc's from PHPrunner support documentation" replace red with your values:
[font="Verdana, Geneva, Arial, sans-serif"][size="2"]1. Set the date control value to 12/24/19 as a string date.[/size]
[font="Verdana, Geneva, Arial, sans-serif"][size="2"][size="2"]//string date

var ctrl = Runner.getControl(pageid, '[color="#ff0000"]datefield');

ctrl.setValue('
[/size]
[font="Verdana, Geneva, Arial, sans-serif"][size="2"]2. Set the date control value as a Javascript Date object.[/size]
[font="Verdana, Geneva, Arial, sans-serif"][size="2"][size="2"]//javascript date object

var ctrl = Runner.getControl(pageid, '[color="#ff0000"]datefield');

var js_date = new Date('');

ctrl.setValue(js_date);[/size]
[/size]
[font="Verdana, Geneva, Arial, sans-serif"][size="2"]3. Set the date control value as a current date with a Moment.js object.[/size]
[font="Verdana, Geneva, Arial, sans-serif"][size="2"][size="2"]//Moment.js date object

var ctrl = Runner.getControl(pageid, '[color="#ff0000"]datefield');

var moment_date = moment();

ctrl.setValue(moment_date);[/size]
[/size]
[font="Verdana, Geneva, Arial, sans-serif"][size="2"]

Note: replace "datefield" with the actual field name in the function.[/size]

M
Melanie authorDevClub member 7/26/2019

Getting very close now:
var ctrlcheckin = Runner.getControl(pageid, 'check_in_date');

var ctrlcheckout = Runner.getControl(pageid, 'check_out_date');

var ctrlsubject = Runner.getControl(pageid, 'Subject_line_for_email');
function func() {

ctrlsubject.setValue( ctrlsubject.getStringValue() + ' - ' + ctrlcheckin.getStringValue() + ' - ' + ctrlcheckout.getStringValue() );

};

ctrlcheckin.on('keyup', func);

ctrlcheckout.on('keyup', func);
But I get this???
last name, first name - 7 - - 7/ - - 7/1 - - 7/1/ - - 7/1/1 - - 7/1/19 - - 7/1/19 - - 7/1/19 - 7 - 7/1/19 - 7/ - 7/1/19 - 7/2 - 7/1/19 - 7/20 - 7/1/19 - 7/20/ - 7/1/19 - 7/20/1 - 7/1/19 - 7/20/19

M
Melanie authorDevClub member 7/26/2019



Getting very close now:
var ctrlcheckin = Runner.getControl(pageid, 'check_in_date');

var ctrlcheckout = Runner.getControl(pageid, 'check_out_date');

var ctrlsubject = Runner.getControl(pageid, 'Subject_line_for_email');
function func() {

ctrlsubject.setValue( ctrlsubject.getStringValue() + ' - ' + ctrlcheckin.getStringValue() + ' - ' + ctrlcheckout.getStringValue() );

};

ctrlcheckin.on('keyup', func);

ctrlcheckout.on('keyup', func);
But I get this???
last name, first name - 7 - - 7/ - - 7/1 - - 7/1/ - - 7/1/1 - - 7/1/19 - - 7/1/19 - - 7/1/19 - 7 - 7/1/19 - 7/ - 7/1/19 - 7/2 - 7/1/19 - 7/20 - 7/1/19 - 7/20/ - 7/1/19 - 7/20/1 - 7/1/19 - 7/20/19


Got it! the 'keyup' was obviously not what I was wanting! Changed to this:
var ctrlcheckin = Runner.getControl(pageid, 'check_in_date');

var ctrlcheckout = Runner.getControl(pageid, 'check_out_date');

var ctrlsubject = Runner.getControl(pageid, 'Subject_line_for_email');
function func() {

ctrlsubject.setValue( ctrlsubject.getStringValue() + ' - ' + ctrlcheckin.getStringValue() + ' - ' + ctrlcheckout.getStringValue() );

};
ctrlcheckout.on('onfocusout', func);
Works perfectly now.

lefty 7/26/2019



Getting very close now:
var ctrlcheckin = Runner.getControl(pageid, 'check_in_date');

var ctrlcheckout = Runner.getControl(pageid, 'check_out_date');

var ctrlsubject = Runner.getControl(pageid, 'Subject_line_for_email');
function func() {

ctrlsubject.setValue( ctrlsubject.getStringValue() + ' - ' + ctrlcheckin.getStringValue() + ' - ' + ctrlcheckout.getStringValue() );

};

ctrlcheckin.on('keyup', func);

ctrlcheckout.on('keyup', func);
But I get this???
last name, first name - 7 - - 7/ - - 7/1 - - 7/1/ - - 7/1/1 - - 7/1/19 - - 7/1/19 - - 7/1/19 - 7 - 7/1/19 - 7/ - 7/1/19 - 7/2 - 7/1/19 - 7/20 - 7/1/19 - 7/20/ - 7/1/19 - 7/20/1 - 7/1/19 - 7/20/19


Okay great . I learned something as well.

M
Mark Kramer 7/26/2019



Okay great . I learned something as well.


I know you did not ask for this but I ran into date subtraction / addition issues when I tried to do something like what you are doing with dates and times.. So thought it might help.. (Used it the "Javascript OnLoad event" of the page)
var DO = new Date(CD.getValue()); //date opened

var DOP = Date.parse(DO) // Grab value and covert it to 'ms' so it is an usable number instead of a string

var dp = Date.parse(d) // Grab value and covert it to 'ms' so it is an usable number instead of a string
// get total seconds between the times

var delta = Math.abs(dp - DOP) / 1000;
// calculate (and subtract) whole days

var days = Math.floor(delta / 86400);

delta -= days 86400;
// calculate (and subtract) whole hours

var hours = Math.floor(delta / 3600) % 24;

delta -= hours
3600;
// calculate (and subtract) whole minutes

var minutes = Math.floor(delta / 60) % 60;

delta -= minutes * 60;
// what's left is seconds

var seconds = delta % 60;
=(days)+" day(s) "+(hours)+" hr(s) "+(minutes)+" min "+(seconds)+" sec "
[color="#FF0000"]TO.setValue(tto);
Red of course are your own varables..

lefty 7/27/2019



I know you did not ask for this but I ran into date subtraction / addition issues when I tried to do something like what you are doing with dates and times.. So thought it might help.. (Used it the "Javascript onload event" of the page)
var DO = new Date(CD.getValue()); //date opened

var DOP = Date.parse(DO) // Grab value and covert it to 'ms' so it is an usable number instead of a string

var dp = Date.parse(d) // Grab value and covert it to 'ms' so it is an usable number instead of a string
// get total seconds between the times

var delta = Math.abs(dp - DOP) / 1000;
// calculate (and subtract) whole days

var days = Math.floor(delta / 86400);

delta -= days 86400;
// calculate (and subtract) whole hours

var hours = Math.floor(delta / 3600) % 24;

delta -= hours
3600;
// calculate (and subtract) whole minutes

var minutes = Math.floor(delta / 60) % 60;

delta -= minutes * 60;
// what's left is seconds

var seconds = delta % 60;
=(days)+" day(s) "+(hours)+" hr(s) "+(minutes)+" min "+(seconds)+" sec "
[color="#FF0000"]TO.setValue(tto);
Red of course are your own varables..


You should put this code in tips and tricks . It would help a lot of users. Thanks.