Debugging JavaScript Assign in Pflow

 8 Replies
 0 Subscribed to this topic
 52 Subscribed to this forum
Sort:
Author
Messages
Woozy
Veteran Member
Posts: 709
Veteran Member
I am building a flow where I am trying to build some fairly complex logic in JavaScript assign nodes.  I'm getting an "Error Evaluating Expression..." message in the log, but that isn't very helpful.

Is there any way to do a "display" of some sort within the node so I can see what it is doing at various steps in the JavaScript?

Thanks!
Kelly Meade
J. R. Simplot Company
Boise, ID
Shane Jones
Veteran Member
Posts: 460
Veteran Member
Is it something you could split apart and do in steps within a number of assign nodes instead of just one node so you could see each part of your script separately?
Shane Jones
Tools: HR, Payroll, Benefits, PFI, Smart Office, BSI, Portal and Self-Service
Systems: Lawson, Open Hire, Kronos, Crystal Reporting, SumTotal Learning
** Teach others to fish...
Woozy
Veteran Member
Posts: 709
Veteran Member
Hi Shane - that is what I generally do, but I thought maybe there was another approach I didn't know about.
Kelly Meade
J. R. Simplot Company
Boise, ID
David Williams
Veteran Member
Posts: 1127
Veteran Member
Are you using the Add Javascript feature to key your script or going into the variable to build your JavaScript Expression? It might be more user friendly if you could see your script as multiple lines instead of one long line.
David Williams
Woozy
Veteran Member
Posts: 709
Veteran Member
I'm using the "Add Javascript" feature.  In this case, I'm doing a significant amount of IF-THEN logic, along with some work with regular expressions to clean and format phone numbers.  My code populates a number of different variables within the single Assign based on the logic.
Kelly Meade
J. R. Simplot Company
Boise, ID
jamesraceson
Veteran Member
Posts: 52
Veteran Member
Woozy,

What I have found in the past is that when you are doing a large amount of Javascript in the "Add Javascript" feature that PF sometimes has problems evaluating the code. The error you are recieving is unfortunately the all too common error that pops up anytime that PF has problem with any of the values/variables within the script. Sometimes it's Null values, sometimes it's wrong types used in calcutations or comparisons and sometimes it's punctuation. What I have found that helps me to troubleshoot is to create a function in the pflow.js file (on the client side for testing) that is a copy of your IF-THEN logic. From here you can pass the required variables (from PF) to the function (to pflow.js) and evaluate each step to see where in your large IF-THEN logic something could be going wrong. Make sure to follow the exact format as the other functions already in the pflow.js file (very important). Once you are done, you then can restore the pflow.js file back to what it was and continue on.
Woozy
Veteran Member
Posts: 709
Veteran Member
Thanks James - very interesting idea.  I don't understand how this helps you evaluate each step of the logic.  Does this allow you to debug the pflow.js file by setting breakpoints or something?  I don't have much experience with js, but that would seem logical.
Kelly Meade
J. R. Simplot Company
Boise, ID
jamesraceson
Veteran Member
Posts: 52
Veteran Member
Woozy,

Understood. Well, unfortunately this process does involve Javascript quite a bit. It would take me a while to write out each step in detail that you would need to do in order to accomplish this, but let me spread out a basic plan.

1) Create a function in the pflow.js file on your client machine

2) Copy your IF-THEN logics to the function

3) Pass your PF variables to the function (you will have to make sure the function has enough arguements for each variable)

4) Comment out each IF-THEN "step" just leaving the first one

5) Put a return statement that passes back either the evaluated variable that you originally passed (to verify that the statements works correctly and that the function recieved the correct value) or pass back the result of your THEN portion of the statement

6) In your PF have the assign node assign a variable that is the result of the function (e.g. your_variable = function_name(var1, var2, var3, etc.))

7) Look at the value of your_variable (in the PF log or in the bottom output screen in PF) to see what is being returned

8) Repeat this for each part of the IF-THEN statement in the function uncommenting each part after you verify that you are getting back what you expect from the statement
Woozy
Veteran Member
Posts: 709
Veteran Member
Ahhh - I understand what you're doing.  That's very helpful!  Thanks...
Kelly Meade
J. R. Simplot Company
Boise, ID