1function OptionSetValue(value) { 2 return { Value: value }; 3} 4function Money(value) { 5 return { Value: value }; 6} 7function EntityReference(logicalName, id, name) { 8 return { 9 LogicalName: logicalName, 10 Id: id, 11 Name: name 12 }; 13} 14 15function XrmOrganizationService() { 16 17 18} 19 20 21function translateAttributesForModelBinder(record, attributes) { 22 23 $.each(attributes, function (key, value) { 24 // only submit updated values. 25 if (attributes._dirty && attributes._dirty[key]) { 26 switch (key) { 27 case "id": 28 case "reference": 29 case "_new": 30 case "_dirty": 31 case "validationResults": 32 break; 33 default: 34 record[key] = value; 35 break; 36 } 37 } 38 }); 39} 40XrmOrganizationService.prototype.retrieveMultiple = function (fetchXml) { 41 fetchXml = encodeURIComponent(fetchXml); 42 return $.post(window.applicationBaseUrl + "XrmService/RetrieveMultiple", $.toDictionary({ "fetchxml": fetchXml })); 43}; 44XrmOrganizationService.prototype.retrieve = function (entityName, id, attributes) { 45 return $.post(window.applicationBaseUrl + "XrmService/Retrieve", $.toDictionary({ "entityName": entityName, "id": id, "attributes": attributes })); 46}; 47XrmOrganizationService.prototype.create = function (entityName, attributes) { 48 var record = { 49 "Id": attributes.id, 50 "LogicalName": entityName 51 }; 52 translateAttributesForModelBinder(record, attributes); 53 return $.post(window.applicationBaseUrl + "XrmService/Create", $.toDictionary(record)); 54}; 55XrmOrganizationService.prototype.update = function (entityName, recordId, attributes) { 56 var record = { 57 "LogicalName": entityName, 58 "Id": recordId 59 }; 60 translateAttributesForModelBinder(record, attributes); 61 return $.post(window.applicationBaseUrl + "XrmService/Update", $.toDictionary(record)); 62}; 63XrmOrganizationService.prototype.deleteRecord = function (entityName, recordId) { 64 var reference = { 65 "entityName": entityName, 66 "id": recordId 67 } 68 return $.post(window.applicationBaseUrl + "XrmService/Delete", $.toDictionary(reference)); 69}; 70 71 72function setEntityValue(entityName, recordId, attributeName, value, callback) { 73 return $.post(window.applicationBaseUrl + "XrmForm/SetValue", { entityName: entityName, recordId: recordId, attributeName: attributeName, value: value }, function () { 74 if ($.isFunction(callback)) { 75 callback.apply(); 76 } 77 }).fail(function (err) { 78 addNotification("setEntityValue", 2, err, true); 79 }); 80} 81function setEntityStatus(entityName, recordId, state, status, callback) { 82 return $.post(window.applicationBaseUrl + "XrmForm/SetStatus", { entityName: entityName, entityId: recordId, state: state, status: status }, function () { 83 if ($.isFunction(callback)) { 84 callback.apply(); 85 } 86 }).fail(function (err) { 87 addNotification("setEntityStatus", 2, err, true); 88 }); 89} 90function saveRecord(record, done, fail) { 91 return $.post(window.applicationBaseUrl + "XrmForm/Update", record, function (response) { 92 if ($.isFunction(done)) { 93 done.apply(response.id); 94 } 95 }).fail(function (error, status) { 96 if ($.isFunction(fail)) { 97 fail.apply(error, status); 98 } else { 99 addNotification("SaveRecord", 2, error.responseText, true); 100 } 101 }); 102} 103 104function pollAttributeValue(entityName, recordId, statusAttribute, inProgressValue, callback) { 105 var svc = new XrmOrganizationService(); 106 svc.retrieve(entityName, recordId, [statusAttribute], function (record) { 107 if (record.Attributes[0].Value == inProgressValue) { 108 setTimeout(pollAttributeValue, 3333, entityName, recordId, statusAttribute, inProgressValue, callback); 109 } else { 110 if ($.isFunction(callback)) { 111 callback(record); 112 } 113 } 114 });
115} 116function pollTaskStatus(entityName, recordId, statusAttribute, callback) { 117 var operationStatus = { 118 NotStarted: 350260000, 119 InProgress: 350260001, 120 Complete: 350260002, 121 Failed: 350260003 122 } 123 return $.post("/XrmForm/GetOperationsStatus", { entityName: entityName, recordId: recordId, statusAttribute: statusAttribute }, function (result) { 124 if (result.OperationStatus == operationStatus.InProgress) { 125 setTimeout(pollTaskStatus, 3333, entityName, recordId, statusAttribute, callback); 126 } else { 127 if ($.isFunction(callback)) { 128 callback(result.OperationStatus); 129 } 130 } 131 }).fail(function (err) { 132 if ($.isFunction(callback)) { 133 callback(operationStatus.Failed); 134 } 135 }); 136} 137 138 139function createGuid() { 140 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { 141 var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); 142 return v.toString(16); 143 }); 144} 145 146 147function Attribute(entity, logicalname) { 148 this.logicalName = logicalname; 149 this.entity = entity; 150} 151Attribute.prototype.getValue = function () { return this.entity.record[logicalName] || null; } 152Attribute.prototype.setValue = function (value) { 153 if (value == null) { value = ""; } 154 var curVal = this.entity.record[this.logicalName] || ""; 155 if (curVal != null && curVal.hasOwnProperty("Value")) { curVal = curVal.Value; } 156 if (curVal != null && curVal.hasOwnProperty("Id")) { curVal = curVal.Id; } 157 158 var newVal = value || ""; 159 if (newVal != null && newVal.hasOwnProperty("Value")) { newVal = newVal.Value; } 160 if (newVal != null && newVal.hasOwnProperty("Id")) { newVal = newVal.Id; } 161 162 if (curVal != newVal) { 163 this.entity.record._dirty = this.entity.record._dirty || {}; 164 this.entity.record._dirty[this.logicalName] = true; 165 this.entity.record[this.logicalName] = newVal; 166 } 167} 168Attribute.prototype.getIsDirty = function () { return this.entity.record._dirty && this.entity.record._dirty[this.logicalName]; } 169 170function Entity(gridrecord) { 171 this.record = gridrecord; 172} 173Entity.prototype.getAttribute = function (logicalname) { 174 return new Attribute(this, logicalname); 175}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.