Page 1 of 1
Expressions
Posted: 27 Jul 2014, 16:00
by ryanair10
How do I make an expression to display the following:
in Sop_Item "Comment_1" in sales ordering I type 600*600 can I make a expression that will multiply 600*600 as a value
Re: Expressions
Posted: 28 Jul 2014, 11:23
by Geordie
While it is possible, I wouldn't recommend what you are trying. Easier would be to use both comment fields. So comment 1 is 600 and comment 2 is 600.
You can the do Stringtointeger(Invoice_item.comment_1) * Stringtointeger(invoice_item.comment_2)
This will the. Give the result.
Otherwise you would be looking at 3 separate expressions breaking down the original 600x600 into two parts then being multiplied.
Re: Expressions
Posted: 01 Aug 2014, 14:24
by brucedenney
Geordie has assumed that the numbers are always whole numbers and is using StringToInteger if this is not the case ie 45.5 * 123.6 then you need to use StringToFloat.
There is no reason not to use expressions to chop up the comment to extract the parts you want (although it is more simple to use 2 fields).
You could use Substring("The String to retrieve a substring from.", "The index of the start of the substring.", "The number of characters in the substring.") to chop it up.
You need to know where the "*" is to get the length for the first part and the start for the second part.
You can use IndexOf("The String to search in.", "The String to seek.") IndexOf(INVOICE_ITEM.COMMENT_1,"*")
Part 1 = Substring(INVOICE_ITEM.COMMENT_1, 0, IndexOf(INVOICE_ITEM.COMMENT_1,"*"))
Part 2 =Substring(INVOICE_ITEM.COMMENT_1, IndexOf(INVOICE_ITEM.COMMENT_1,"*"),60)
the 0 may need to be a 1 you may need to add/subtact 1 from the index of part to not include the * )
You can then turn them into numbers.
Part 1 = StringToFloat(Substring(INVOICE_ITEM.COMMENT_1, 0, IndexOf(INVOICE_ITEM.COMMENT_1,"*")))
Part 2 =StringToFloat(Substring(INVOICE_ITEM.COMMENT_1, IndexOf(INVOICE_ITEM.COMMENT_1,"*"),60))
and multiply the two together
StringToFloat(Substring(INVOICE_ITEM.COMMENT_1, IndexOf(INVOICE_ITEM.COMMENT_1,"*"),60))*StringToFloat(Substring(INVOICE_ITEM.COMMENT_1, 0, IndexOf(INVOICE_ITEM.COMMENT_1,"*")))
I have not checked this I included the warnings above on how you may need to tweak this.
You want to build up the expression bit by bit and check each bit as you go.