Hello All~
I'm working on a very simple script in CRM 2016 that will auto name the Subject of a Phone Call activity with the name of the Call To (or Call From based on the direction). I have the code working as expected with the exception if I delete the Call To (for from), I get the below error messages. I tried a try/catch in my code but that isn't catching these errors. What is the best way to handle this? Code below
TypeError: Cannot read property 'name' of undefined
TypeError: Cannot read property '0' of null
function autonaming() {
var callTo = Xrm.Page.getAttribute("to").getValue()[0].name;
var callFrom = Xrm.Page.getAttribute("from").getValue()[0].name;
var taskCat = Xrm.Page.data.entity.attributes.get("vacu_taskcategorycode").getText();
var direction = Xrm.Page.getAttribute("directioncode").getValue();
if (direction) {
subject = Xrm.Page.getAttribute("subject").setValue( callTo + " - " + taskCat);
} else {
subject = Xrm.Page.getAttribute("subject").setValue( callFrom + " - " + taskCat);
}
};
Thank you,
Chrys
*This post is locked for comments