So i got a weird error of "t.name.replace is not a function" when using Javascript formContext.getAttribute().SetValue() on a lookup column. The idea i want to achieve here is that i want to dynamically set a lookup column depending on what Choice Column we pick in the main form. Then use a Display->Form Component to display a couple of related columns according to the lookup column.
I put the javascript code on the OnChange trigger of the Choice Column. As for mapping what choice column value will set what value to the lookup table, i have a dedicated table for that. All choices will have a one to one relation with the lookup value/id. The javascript will simply query the necessary data to set the lookup column. And this setup works somewhat, but only when the choice column is set to a new choice/lookup id. If it is changed to the same choice as the one it is saved on the dataverse, it will produce the error. The weird thing is, i checked the values of "lookupValue" and it should be right. Is this a bug from microsoft end?
function dynamicApproval(executionContext) { //On Change di Approval Path
var formContext = executionContext.getFormContext();
var approvalid = formContext.getAttribute("bkp_approvalpath").getValue();
var Retrievepromise = retrieveApproval(approvalid)
Retrievepromise.then(
success => {
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].entityType = "bkp_perjalanandinasapproval";
lookupValue[0].id = success.bkp_perjalanandinasapprovalid;
lookupValue[0].name = approvalid;
var approverid = success.bkp_approverid
try {
formContext.getAttribute("bkp_approverid").setValue(approverid);
formContext.getAttribute("bkp_approval").setValue(lookupValue); //THE LINE CAUSING THE CATCH
}
catch (err) {
alert("Error: " + err.message); //THE LINE CAUSING THE ALERT
}
},
failure => {
alert("Retrieve Approval Failed")
}
)
}
async function retrieveApproval(approvalid) { //Retrieve Approval for Dynamic Approval
try {
const record = await Xrm.WebApi.retrieveMultipleRecords("bkp_perjalanandinasapproval", "?$select=bkp_perjalanandinasapprovalid,bkp_approverid&$filter=bkp_name eq '" + approvalid + "'");
return record.entities[0]
}
catch (err) {
alert(err.message);
}
}
Stay up to date on forum activity by subscribing.
stampcoin
58
DS-11051211-0
20
HumanOnly
6