Jump to content

Maths formula based on capture answers


LawesD

Recommended Posts

Hi all, 

I am trying to get a maths formula to work which will then be put in an update on the request, any help will be appreciated.

This will be based on numbers that are entered by an analyst into the capture fields on a task. The phrasing of it seems to run normally when I substitute the formula with straight numbers e.g.:

&[((22+33)/983)*(113*1.2).toFixed(2)] - All working

When I try the same thing with the capture answers I get NaN (not a number) as a response:

&[(([functions.getTaskAnswers("task-44cac0db-0cc1-4d25-5182-6a243f56c4f8").h_custom_a]+[functions.getTaskAnswers("task-44cac0db-0cc1-4d25-5182-6a243f56c4f8").h_custom_b])/983)*([functions.getTaskAnswers("task-44cac0db-0cc1-4d25-5182-6a243f56c4f8").field_3]*1.2).toFixed(2)]

The fields seem to populate and I have nodes, rescanning both request details and PCF answers, before I have added the formula just in case.

The values I have entered into the task appear correctly when displaying as custom fields in the job info.

image.png.04ca58f2a151412c2afc2d2b3ccc9288.png

Link to comment
Share on other sites

@LawesD 

  • You are using the answers which are always characters/strings. Try and convert them before applying math formulas to them. Try using: parseInt()
  • If you are to use the custom fields values (instead of answers) please be aware that custom A and custom B are not numeric fields.
Link to comment
Share on other sites

Hi @Victor, thanks for the reply. 

I've tried to use the custom fields 26 - 28 as they specified (INTEGER). This returns me a result of '0' which is at least a number so progress! As below:

&[(([global["flowcode"]["customField26"]]+[global["flowcode"]["customField27"]])/983)*([global["flowcode"]["customField28"]]*1.2).toFixed(2)]

I'm not sure where the parseInt() would fit into this expression - I'm a layman to this but we managed to get similar things working when the answers were taken directly from the real PCF field.

Link to comment
Share on other sites

Thank you!

So the answers are input into the capture fields of the task, they relate to 3D printing. Most have default answers but the volumes will change per job.

So the formula is  ((Material volume + Support material volume) /983) * Material cost *1.2) 

image.png.aee32ec07fe415b8b28a50c604f76b10.png

And here as the analyst sees it:

image.png.7a1169a9c9c2dc82d934a759a29973c3.png

Link to comment
Share on other sites

@LawesD try one of these:

&[(([functions.getTaskAnswers("task-44cac0db-0cc1-4d25-5182-6a243f56c4f8").h_custom_a]*1.00+[functions.getTaskAnswers("task-44cac0db-0cc1-4d25-5182-6a243f56c4f8").h_custom_b]*1.00)/983)*([functions.getTaskAnswers("task-44cac0db-0cc1-4d25-5182-6a243f56c4f8").field_3]*1.2).toFixed(2)]

or

&[(([global["flowcode"]["customField26"]]*1.00+[global["flowcode"]["customField27"]]*1.00)/983)*([global["flowcode"]["customField28"]]*1.2).toFixed(2)]

 

Link to comment
Share on other sites

I tip my hat to you. The first one worked with one more set of brackets to segregate the .toFixed 2 bit. 

So the *1.00 seems to calm the value references back into being a proper number? However it worked thank you for all your help. 

 

Image result for westworld reaction gif smile

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...