Hi,
I need to stop the saving of account record if it doesn’t contains the attachment.
Based upon the Onchange event value of the picklist field new_fileAttached (Values = Yes, No).
If the Value = yes and Notes section is having the attachment then I need to save the record.
If the value = Yes then Notes section doesn’t contains the attachment then stop the record and throw error msg.
I have written the below code and called the function OnSave and Onchange events.
Code is working fine if I’m not attaching the file if new_fileAttached = Yes.
But code working for the same in 2013 without attachment just entering the name of the note.
Please let me know where I'm doing wrong, Can someone help me on this will be appreciated.
function getAttachNotes(executionObj) { var recordId = Xrm.Page.data.entity.getId(); var FileAttached = Xrm.Page.data.entity.attributes.get("new_fileAttached").getText(); if (FileAttached == "Yes") { var sFetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + "<entity name='annotation'>" + "<attribute name='annotationid' />" + "<link-entity name='account' from='accountid' to='objectid' alias='ab'>" + "<filter type='and'>" + "<condition attribute='accountid' operator='eq' value='" + recordId + "'/>" + "</filter>" + "</link-entity>" + "</entity>" + "</fetch>" var FetchResults = Fetch(sFetchXml); var AnnotationId = FetchResults.GetValues("annotationid"); if (AnnotationId.length > 0) { } else { alert("You have not added Attachment."); executionObj.getEventArgs().preventDefault(); } } }
Thanks,
Rahul