LawesD Posted August 30, 2018 Share Posted August 30, 2018 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. Link to comment Share on other sites More sharing options...
Victor Posted August 30, 2018 Share Posted August 30, 2018 @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 More sharing options...
LawesD Posted August 30, 2018 Author Share Posted August 30, 2018 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 More sharing options...
Victor Posted August 30, 2018 Share Posted August 30, 2018 Indeed, a different error or issue is always progress! I'll try your scenario in my instance, what values you populate for those variables? I mean what answers you provide during PCF? Link to comment Share on other sites More sharing options...
LawesD Posted August 30, 2018 Author Share Posted August 30, 2018 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) And here as the analyst sees it: Link to comment Share on other sites More sharing options...
Victor Posted August 30, 2018 Share Posted August 30, 2018 @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 More sharing options...
LawesD Posted August 30, 2018 Author Share Posted August 30, 2018 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. Link to comment Share on other sites More sharing options...
Victor Posted August 30, 2018 Share Posted August 30, 2018 @LawesD - I think the multiplier operation can distinguish numbers from stings and results in a number... I'm happy it worked ... well as happy as a park director can be... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now