![]() |
#5 |
Kostya Afendikov
|
Цитата:
Поле: "Продукт" Событие: "OnChange", вставите следующий код X++: if (crmForm.all.productid.DataValue != null) { var resultXml; var result; var xml; var id = crmForm.all.productid.DataValue[0].id; id = id.replace("{", ""); id = id.replace("}", ""); var xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + " <soap:Body>" + " <entityName xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">product</entityName>" + " <id xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + id + "</id>" + " <columnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\" xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + " <q1:Attributes>" + " <q1:Attribute>defaultuomid</q1:Attribute>" + " </q1:Attributes>" + " </columnSet>" + " </soap:Body>" + "</soap:Envelope>" + ""; var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false); xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/Retrieve"); xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlHttpRequest.setRequestHeader("Content-Length", xml.length); xmlHttpRequest.send(xml); resultXml = xmlHttpRequest.responseXML; result = ReadXml(xmlHttpRequest.responseXML); try { defaultvalueid = result.Envelope.Body.RetrieveResult.defaultuomid; if (isdefined(defaultvalueid)) { var lookupData = new Array(); var lookupItem= new Object(); lookupItem.id = defaultvalueid.value; lookupItem.typename = 'uom'; lookupItem.name = defaultvalueid.xmlAttributes.name; lookupData[0] = lookupItem; } else { lookupData = null; } crmForm.all.uomid.DataValue = lookupData; } catch(e) { crmForm.all.uomid.DataValue = null; } } else { } if(crmForm.all.quantity.DataValue == null) { //crmForm.all.quantity = new Object(); crmForm.all.quantity.DataValue = 0.0; } if((crmForm.all.productid != null) && (crmForm.all.uomid != null)) { crmForm.Save(); } function ReadXml(oXml) { var oReturnValue = new Object(); if (IsNull(oXml)) { return oReturnValue; } var childNodes = oXml.childNodes; for (var i = 0; i < childNodes.length; i++) { var oChildNode = childNodes.item(i); switch (oChildNode.nodeType) { case 1: var oChildObject = ReadXml(oChildNode); if (IsNull(oReturnValue[oChildNode.baseName])) { oReturnValue[oChildNode.baseName] = oChildObject; } else { if (!isArray(oReturnValue[oChildNode.baseName])) { var property = oReturnValue[oChildNode.baseName]; oReturnValue[oChildNode.baseName] = new Array(); oReturnValue[oChildNode.baseName].push(property); } oReturnValue[oChildNode.baseName].push(oChildObject); } break; case 3: oReturnValue["value"] = fromString(oChildNode.nodeValue); break; case 4: return oChildNode.text; default: break; } } if (IsNull(oReturnValue.xmlAttributes)) { var attributes = oXml.attributes; if (!IsNull(attributes)) { if (attributes.length > 0) { oReturnValue.xmlAttributes = new Object(); for (var i = 0; i < attributes.length; i++) { oReturnValue.xmlAttributes[attributes.item(i).baseName] = fromString(attributes.item(i).nodeValue); } } } } return oReturnValue; } function fromString(sValue) { if (sValue.toLowerCase() == "true") { return true; } else if (sValue.toLowerCase() == "false") { return false; } var intValue = parseInt(sValue, 10); if (!isNaN(intValue) && intValue.toString() == sValue) { return intValue; } var floatValue = parseFloat(sValue); if (!isNaN(floatValue) && floatValue.toString() == sValue) { return floatValue; } var dateValue = new Date(sValue); if (!isNaN(dateValue)) { return dateValue; } return sValue; } function isdefined( variable) { return (typeof(variable) == "undefined")? false: true; } |
|
|
За это сообщение автора поблагодарили: e.pasechny (1), Elka (1). |
|
|