Hi Paul,
I think there is no need for javascript. Just add a OnChange action on your radiobuttons and set the RefCode there.
Edit: if you really want to use javascript to set the value, here is a possible solution. Note that I am using the Enum-Keys in the case statement.
This is a fragile construct, as changes in the enumeration will not be checked and there is afaik no builtin model reflection for javascript actions. I would generally not recommend doing this.
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import { Big } from "big.js";
// BEGIN EXTRA CODE
// END EXTRA CODE
/**
* @param {MxObject} mxobj
* @returns {Promise.<void>}
*/
export async function JavaScript_action(mxobj) {
// BEGIN USER CODE
var state = mxobj.get("CurrentState");
switch (state) {
case "Compliment":
mxobj.set("RefCode", "CMP");
break;
case "Complaint":
mxobj.set("RefCode", "COM");
break;
case "Suggestion":
mxobj.set("RefCode", "SUG");
break;
case "Historic":
default:
mxobj.set("RefCode", "LTE")
break;
}
// END USER CODE
}
Additionally, use the function getCaption() to use the caption value of the enum.