How can I assign the value of a field based on the value of another field. For example if TextField1.value == 1 then this.value = 2.
Solved! Go to Solution.
This can be achieved by writing an expression like this.value = (TextField1.value ==1) * 2 . However if your case is so complex that you cannot derive an expression relating the fields then you can write a service, make an ajax call to it passing the value of TextField1, and return desired value of the field via service and assign the responseText of the field to the value in the calculate expression like
this.value = $.ajax (url: "service_end_point"
data: {valueOfTextField: TextField1.value}
).responseText
This can be achieved by writing an expression like this.value = (TextField1.value ==1) * 2 . However if your case is so complex that you cannot derive an expression relating the fields then you can write a service, make an ajax call to it passing the value of TextField1, and return desired value of the field via service and assign the responseText of the field to the value in the calculate expression like
this.value = $.ajax (url: "service_end_point"
data: {valueOfTextField: TextField1.value}
).responseText
Thanks Mandeep. For now, Deepak solution below works for me but I think when I start to implement more complex solutions, I'll have to refer to your ajax solution.
Views
Replies
Total Likes
Thanks Deepak. Your solution works well for me.
Cheers,
Afam.
Views
Replies
Total Likes
Hi,
I'm wondering if it is possible to have an expression like ( firstname.value == "charles" ) ? "John" : " "; ( firstname.value == "susan" ) ? "morris" : " "; ( firstname.value == "tim" ) ? "michaels" : " "; in my last field calculate expression?
At the moment, it only works correctly for the first expression set i.e. charles but dosen't work for any of the rest.
Thanks Afam.
Views
Replies
Total Likes
Can you try below:
( firstname.value == "charles" ) ? "John" : (( firstname.value == "susan" ) ? "morris" : (( firstname.value == "tim" ) ? "michaels" : ""))
Views
Replies
Total Likes
Hi Deepak,
It didn't work for me. Does it work for you?
Views
Replies
Total Likes
Let's say this in your example point to field2 for which you want to write calculate expression. Open the propertiies(or edit) dialog of field2 in edit mode and in Calculate Expression input box, enter expression:
( TextField1.value == 1) ? 2 : 0
Calculate Expression should be basically a valid javascript expression and should return a value which would be automatically assigned to current field(field2 in above case)
Hi Afam,
This works for me. It gives me "john" in the other field if it inscribe "charles" in the field firstname , "morris" for "susan", "michaels" for "tim" and nothing for any other value. Is it not what you are expecting?
Views
Replies
Total Likes
Hi Deepak,
That is exactly what I expect. When I copy the code you sent in your earlier post and paste it in my last name calculate expression field, I don't get any values for charles, susan or tim. Could there be an error in the code I'm pasting? please see code below.
( firstname.value == "charles" ) ? "John" : (( firstname.value == "susan" ) ? "morris" : (( firstname.value == "tim" ) ? "michaels" : ""))
Views
Replies
Total Likes
Hi Deepak,
Apologies, It does work!
My stupidity. My First Name field was called name. Once I changed it to firstname, code worked!
Thanks mate.
Views
Replies
Total Likes