OK, this is embarrassing but I cannot get my very first calculation in Servoy to work.
existing field (PK) is called name_id
I want to establish a GUID (globally unique id) for each table in the solution so I would like to calcuate the result “NA” (code for the name table) followed by the rightmost 6 characters of “000000” concatenated with the value of name_id.
So I took these steps:
Defined a text field 8 char’s in length called name_guid
Defined a calculation field (also text) choosing names_guid from the drop list as the calc name
wrote this formula, which does not produce an error when I click Verify:
I also tried calculating the string into a variable and then returning the variable:
var guid = "NA" + utils.stringRight("000000"+field.name_id, 6);
return guid;
Clearly I’m just not understanding how to write Servoy calculations! I have read (the tiny amount of) info available in the product documentation but mostly found the info I really needed (such as “how do I concatenate strings?”) here on this forum. tia for any help.
OK, my original formula works fine except that aparently I do not need to specify the field object type by putting “field.” in front of the column name. Which makes me wonder why it’s written like that in this post:
unless maybe it has something to do with a version change since then? or Mattman’s particular style of naming columns with the string “field.” in front of each column name? or what?
tweetie:
did you check the type of the calculation?..i.e. you have to tell Servoy if the result of the calculation is a text,integer, datetime etc
Yes, as per #1 and #2 in my original post on this topic, I did make sure the calculation’s data type is Text. Then I spent some time wondering whether there is some function I need to put around the PK in order for it to be coerced into text, but apparently this is not necessary. It will take a while to get used to how data types work in javascript.
Can anyone explain why the older post I referred to has “field.” in front of the field name? Thanks.
I suspect mattman used the field.predicate to point out the differences between the element branch and the field branch in the method editor treeview. It is a common (newbie or not) mistake to refer to an element named “fieldname” and the field that has the same name
So mattmans example is not code (he would have qouted it as code when it was) but pseudocode to explain a principle