getDisplayValue is not a function and failed IfScript

morgang
Giga Expert

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 &amp;&amp; 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.
6 REPLIES 6

Daniel Draes
ServiceNow Employee
ServiceNow Employee

Hi there,

sorry, the alert is my fault. Somehow I didn't get the workflow part in the beginning. Workflow is surely more server side and alert's will not work there.

I did play around with the workflow scratchpad and it seems the scratchpad cannot store a GlideDateTime object. So I had the same issue as you with a minimalistic workflow just trying to pass a date object from one task to another.

However, I could get it to work by passing the string value via the sctrachpad:

storing:



workflow.scratchpad.ostartDate = new GlideDateTime(current.opened_at).getDisplayValue();


retrieving:


current.work_notes = "Getting ostartdate from scratchpad: " + new GlideDateTime(workflow.scratchpad.ostartDate).getDisplayValue();


Have a try with that.



morgang
Giga Expert

Great, thanks for your help! I took all the glide dates off the scratchpad and replaced them with the .getDisplayValue() then when needed as glide dates used a variable using your

new GlideDateTime(workflow.scratchpad.ostartDate)

example and it started working.

Thank you very much for your time and assistance!

-mg