I'm getting a record using fetch to client side, and I need to fill the data from the fetch into a field in a new record I create (fill field on client side), but when I use set value I get an error: Cannot read property 'setValue' of null, I don't understand why, the field is Null because the new record is empty, why can't I fill it ?
function OnLoad() { formType = Xrm.Page.ui.getFormType(); if(formType == formTypes.Create ){ copyCatNewRecord(); } } function copyCatNewRecord(){ var xml; xml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='1'>" xml += "<entity name='needs'>" xml += "<attribute name='needsid' />" xml += "<attribute name='needsname' />" xml += "<order attribute='modifiedon' descending='true' />" xml += "</entity></fetch>" var ret = frameworkGlobal.ExecuteFetchRequest(xml); var currValue = ret[0].needsid.Value; // this line returns an error Xrm.Page.getAttribute("needs").setValue(currValue ); }