getDisplayValue is not a function and failed IfScript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2013 06:08 PM
After the fact edit:
The root of my problem was I was trying to store glide dates on the scratchpad. The solution, with many thanks to Mr. Dräs (Fogg), was to store the display values of the dates on the scratchpad and then if needed as glide dates in activities, build the glide dates locally using the display values.
-=-
I'm trying to check for deployment readiness by checking if the start date field changed and if the state of my change is appropriate. Since the date hasn't changed in my examples timedif should be 0. current.state when written to the work log is -40.
For some reason it seems to not be getting that far - hoping for assistance with why?
My variables are populated with (seems to work based on what it writes to info messages 😞
workflow.scratchpad.ostartDate = new GlideDateTime(current.start_date); workflow.scratchpad.aostartDate = new GlideDateTime(current.start_date); workflow.scratchpad.aostartDate.addSeconds(-180); gs.addInfoMessage("Planned autostart is " + workflow.scratchpad.aostartDate.getDisplayValue()+". If that is not a good time to deploy, change the Deployment Start Date to prevent automatic scheduling."); gs.addInfoMessage("Autostart is " + workflow.scratchpad.aostartDate.getDisplayValue()+"Current start date is: "+current.start_date.getDisplayValue()+' and Original start date is: '+workflow.scratchpad.ostartDate.getDisplayValue()); var seconds = parseFloat(gs.dateDiff(gs.nowDateTime(),workflow.scratchpad.aostartDate.getDisplayValue(), true)); gs.addInfoMessage('Waiting '+seconds + ' seconds until automatic start.');
But this code throws the error about getDisplayValue not being a function:
function determineDeploymentReadiness() { try { current.work_notes = 'Comparing '+current.start_date.getDisplayValue()+' vs '+workflow.scratchpad.ostartDate.getDisplayValue(); gs.addInfoMessage('Comparing '+current.start_date.getDisplayValue()+' vs '+workflow.scratchpad.ostartDate.getDisplayValue()); var timedif = parseFloat(gs.dateDiff(current.start_date.getDisplayValue(),workflow.scratchpad.ostartDate.getDisplayValue(),true)); current.work_notes = 'Time: '+timedif+ typeof(timedif)+' state'+current.state+ typeof(current.state); // if (timedif ==0 && current.state < 15) { workflow.scratchpad.DeploymentReady = true; } else { workflow.scratchpad.DeploymentReady = false; } current.work_notes += 'Deployment readiness: ' + workflow.scratchpad.DeploymentReady; gs.addInfoMessage('Deployment readiness: ' + workflow.scratchpad.DeploymentReady); } catch (err) { gs.addInfoMessage("Error is " + err); current.work_notes = "Error caught: " + err; } } determineDeploymentReadiness();
In the worklog it says:
Error caught: TypeError: getDisplayValue is not a function.
I hope to follow this with an IfScript where the answer = workflow.scratchpad.DeploymentReady; but it seems the above code isn't defining DelopymentReady to let the if condition return anything other than no. Thank you for any help offered; I've been banging away at this for 3 days now.
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2013 02:14 AM
Hi morgang,
i would assume that by the time your script runs the values in the scratchpad are not yet set. Therefor getDisplayValue cannot be executed. Try adding a check if the values are initialized in the scratchpad and exit if not.
Other than that I am wondering of you actually need getDisplayValue for the strings to compare with gs.datediff. Would assume this works without, even though I have not tried it yet.
Daniel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2013 09:07 AM
Thank you for the reply and for taking a look.
Added a runscript to write out the variables to the log when they're created to confirm variables are set:
current.work_notes = "Checking variables are set. \nAutostart is " + workflow.scratchpad.aostartDate.getDisplayValue()+"\n Currrent Start Date:" +current.start_date.getDisplayValue()+'\nOriginal start date: '+workflow.scratchpad.ostartDate.getDisplayValue()+'\nSeconds before autostart '+seconds;
which outputs (consistent with intended):
Checking variables are set.
Autostart is 2013-04-10 09:28:45
Currrent Start Date:2013-04-10 09:31:45
Original start date: 2013-04-10 09:31:45
Seconds before autostart 60
I have a wait condition (which works - happily green in the workflow diagram waiting for aostartdate which is 3 minutes before) with:
answer = parseFloat(gs.dateDiff(gs.nowDateTime(),workflow.scratchpad.aostartDate.getDisplayValue(), true));
This doesn't contain other code that (at least in my mind) would write to the scratchpad, but after this step my scratchpad dates seem to stop working.
Removing the .getDisplayValue gives me undefined when writing to the work log and makes my time difference negative in gs.dateDiff.
To try to cut out getDisplayValue() as much as possible, I tried setting workflow.scratchpad.ostartDate = current.start_date.getDisplayValue(); and removing the .getDisplayValue() everywhere after.
Since that gave the same behavior of always evaluating to 'no', in each step between setting the variable value and the failure, I added:
current.work_notes = "\n@<name of> step \nChecking variables are set. \nAutostart is " + workflow.scratchpad.aostartDate.getDisplayValue()+"\n Currrent Start Date:" +current.start_date.getDisplayValue()+'\nOriginal start date: (workflow.scratchpad.ostartDate) which keeps coming out undefined later on '+workflow.scratchpad.ostartDate;
Re-ran it with the code above at each step and the log shows:
@Timer wait for AutoStartDate step
Checking variables are set.
Autostart is 2013-04-10 11:52:55
Currrent Start Date:2013-04-10 11:55:55
Original start date: (workflow.scratchpad.ostartDate) which keeps coming out undefined later on 2013-04-10 11:55:55
@Calculate Automatic schedule date step
Checking variables are set.
Autostart is 2013-04-10 11:52:55
Currrent Start Date:2013-04-10 11:55:55
Original start date: (workflow.scratchpad.ostartDate) which keeps coming out undefined later on 2013-04-10 11:55:55
Seconds before autostart 75
(Screenshot of workflow attached - hopefully it helps illustrate the problem. Seems like my scratchpad variable is no longer valid either after the timer - or after the check for active non deployment tasks. The timer uses my other scratchpad date -- and successfully - and the check for tasks does not do anything to the dates.)
-mg

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2013 09:37 AM
Did you try to add something like
function determineDeploymentReadiness() {
alert(workflow.scratchpad.ostartDate);
alert(workflow.scratchpad.ostartDate.getDisplayValue());
try {
current.work_notes = 'Comparing '+current.start_date.getDisplayValue()+' vs '+workflow.scratchpad.ostartDate.getDisplayValue();
gs.addInfoMessage('Comparing '+current.start_date.getDisplayValue()+' vs '+workflow.scratchpad.ostartDate.getDisplayValue());
Just to make sure in the clientscript all arrives ok ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2013 02:41 PM
Alerts don't pop up, before or after the Wait for AutoStartDate step -- catch writes out: "Error upon calculate automatic schedule date is ReferenceError: "alert" is not defined." Wondering if the workflow is more server-side than client for these bits (I'm still learning my way through though). Instead of alert, it writes out to current.work_notes, and before the timer I get infoMessages too.
Found an example of comparing dates which uses numeric values instead of date objects, so tried that method.
That gives similar results (output suggests the value is Na):
In initialization added numericOstartDate:
//workflow.scratchpad.ostartDate = new GlideDateTime(current.start_date);
workflow.scratchpad.ostartDate = current.start_date.getDisplayValue();
workflow.scratchpad.numericOstartDate = current.start_date.getGlideObject().getNumericValue();
Then try writing to the log first when the scratchpad variables are set:
current.work_notes = "\n@Calculate Automatic schedule date step \nChecking variables are set. \nAutostart is " + workflow.scratchpad.aostartDate.getDisplayValue()+"\n Currrent Start Date:" +current.start_date.getDisplayValue()+'\nOriginal start date: (workflow.scratchpad.ostartDate) which keeps coming out undefined later on '+workflow.scratchpad.ostartDate+' Numeric '+workflow.scratchpad.numericOstartDate+'\nSeconds before autostart '+seconds;
current.work_notes += 'workflow.scratchpad.ostartDate: '+workflow.scratchpad.ostartDate;//alert(workflow.scratchpad.ostartDate);
current.work_notes += 'workflow.scratchpad.ostartDate.getDisplayValue() should error out: '+workflow.scratchpad.ostartDate.getDisplayValue();//alert(workflow.scratchpad.ostartDate.getDisplayValue());
current.work_notes +='workflow.scratchpad.numericOstartDatestart:'+workflow.scratchpad.numericOstartDatestart; //alert(workflow.scratchpad.numericOstartDatestart);
Then again when called in checking deployment readiness (basically the same, just trying to use the numeric values):
function determineDeploymentReadiness2() {
try {
var startdateNow = current.start_date.getGlideObject().getNumericValue();
var timedif2 = (startdateNow - workflow.scratchpad.numericOstartDatestart);
current.work_notes = 'Entering determineDeploymentReadiness()\nComparing '+current.start_date.getDisplayValue()+' vs '+workflow.scratchpad.ostartDate+'\n Numeric Start:'+startdateNow+' Numeric Start on Scratchpad: '+workflow.scratchpad.numericOstartDate;
current.work_notes = 'Time: '+timedif2+ typeof(timedif2)+' state'+current.state+ typeof(current.state);
if (timedif2 ==0 && current.state < 15) {
workflow.scratchpad.DeploymentReady = true;
} else {
workflow.scratchpad.DeploymentReady = false;
}
current.work_notes += 'Deployment readiness (2): ' + workflow.scratchpad.DeploymentReady;
current.work_notes += 'workflow.scratchpad.ostartDate: '+workflow.scratchpad.ostartDate;//alert(workflow.scratchpad.ostartDate);
current.work_notes += 'workflow.scratchpad.ostartDate.getDisplayValue() should error out: '+workflow.scratchpad.ostartDate.getDisplayValue();//alert(workflow.scratchpad.ostartDate.getDisplayValue());
current.work_notes +='workflow.scratchpad.numericOstartDatestart:'+workflow.scratchpad.numericOstartDate; //alert(workflow.scratchpad.numericOstartDate);
}
catch (err) {
current.work_notes = "Error caught in determineDeploymentReadiness2(): " + err;
}
}determineDeploymentReadiness2();
Similar to before, the log shows both of the scratchpad variables are undefined after the timer and if blocks:
Error caught in determineDeploymentReadiness2(): TypeError: getDisplayValue is not a function.
Time: NaNnumber state-40object
Entering determineDeploymentReadiness()
Comparing 2013-04-10 16:00:30 vs undefined
Numeric Start:1365624030000 Numeric Start on Scratchpad: undefinedDeployment readiness (2): false
Time: NaNnumber state-40object
Entering determineDeploymentReadiness()
Comparing 2013-04-10 16:00:30 vs undefined
Numeric Start:1365624030000 Numeric Start on Scratchpad: undefinedworkflow.scratchpad.ostartDate: undefined
Time: NaNnumber state-40object
Entering determineDeploymentReadiness()
Comparing 2013-04-10 16:00:30 vs undefined
Numeric Start:1365624030000 Numeric Start on Scratchpad: undefinedDeployment readiness (2): false
Time: NaNnumber state-40object
Entering determineDeploymentReadiness()
Comparing 2013-04-10 16:00:30 vs undefined
Numeric Start:1365624030000 Numeric Start on Scratchpad: undefined
@Timer wait for AutoStartDate step
Checking variables are set.
Autostart is 2013-04-10 15:57:30
Currrent Start Date:2013-04-10 16:00:30
Original start date: (workflow.scratchpad.ostartDate) which keeps coming out undefined later on 2013-04-10 16:00:30
Error upon calculate automatic schedule date is TypeError: getDisplayValue is not a function.
@Calculate Automatic schedule date step
Checking variables are set.
Autostart is 2013-04-10 15:57:30
Currrent Start Date:2013-04-10 16:00:30
Original start date: (workflow.scratchpad.ostartDate) which keeps coming out undefined later on 2013-04-10 16:00:30 Numeric 1365624030000
Seconds before autostart 8
Code in This BOE Change approved for Production deployment.
----------===== Building Production Deployment Task =====----------
Deployment Please Promote This BOE Change to Business Objects Production
----------===== Production Deployment Task Created =====----------
workflow.scratchpad.ostartDate: 2013-04-10 16:00:30
Your question about it arriving on the client makes me wonder -- is there a practical limit to the number of workflow steps or length of script in total or is this actually being pushed to the client for execution there? Publishing the workflow takes longer than it did when it had fewer pieces, but not materially longer to run. (And workflow steps after this seem to work without issue, so I've just been adding steps to fit our process that will save time without trying to minimize size or steps.) I'm puzzled as to why after the wait and task check it seems to destroy the scratchpad variables in the same fashion, whether I store the date as a number, glide date object, or display value. (Assuming I'm reading the results correctly.)
-mg