Hello everyone,
I'm having an issue with a custom script in Dynamics Sales and was hoping to get some help troubleshooting it.
I have a custom script that is triggered on the change of a lookup field called "cr452_tipodemadeira" and is supposed to set the value of another field called "productnumber" to either the value of the "name" attribute or the "cr452_prefixo" attribute of the selected record in the "cr452_tipodemadeira" lookup.
Here are the two versions of the script I've tried:
function COD_MSE() {
var woodType = Xrm.Page.getAttribute("cr452_tipodemadeira").getValue();
if (woodType && woodType.length > 0) {
var nome = woodType[0].name;
Xrm.Page.getAttribute("productnumber").setValue(nome);
} else {
console.log("Nenhum tipo de madeira selecionado.");
}
}
function COD_MSE() {
var woodType = Xrm.Page.getAttribute("cr452_tipodemadeira").getValue();
if (woodType && woodType.length > 0) {
var nome = woodType[0].cr452_prefixo;
Xrm.Page.getAttribute("productnumber").setValue(nome);
} else {
console.log("Nenhum tipo de madeira selecionado.");
}
}
The first version of the script works as expected, but the second version doesn't set the value of the "productnumber" field. I have also added the "cr452_prefixo" attribute to the view associated with the lookup field, but that didn't solve the issue.
Any ideas on what could be causing this issue?
Thank you in advance for your help!