751. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2/1/2017 2:57:02 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

751.1 Files compared

# Location File Last Modified
1 C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\SampleCode\JS\SOAPForJScript\SOAPForJScript\Scripts SDK.MetaData.js Tue Dec 20 19:51:48 2016 UTC
2 Wed Feb 1 19:57:02 2017 UTC

751.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 0 0
Removed 1 768

751.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

751.4 Active regular expressions

No regular expressions were active.

751.5 Comparison detail

1   // ======= ========== ========== ========== ========== ========== ========== ==        
2   //  This f ile is par t of the M icrosoft D ynamics CR M SDK code  samples.        
3   //        
4   //  Copyri ght (C) Mi crosoft Co rporation.   All righ ts reserve d.        
5   //        
6   //  This s ource code  is intend ed only as  a supplem ent to Mic rosoft        
7   //  Develo pment Tool s and/or o n-line doc umentation .  See the se other        
8   //  materi als for de tailed inf ormation r egarding M icrosoft c ode sample s.        
9   //        
10   //  THIS C ODE AND IN FORMATION  ARE PROVID ED "AS IS"  WITHOUT W ARRANTY OF  ANY        
11   //  KIND,  EITHER EXP RESSED OR  IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E        
12   //  IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR  A        
13   //  PARTIC ULAR PURPO SE.        
14   // ======= ========== ========== ========== ========== ========== ========== ==        
15          
16   //<snippet SDK.Metada ta.js>        
17          
18   SDK = wind ow.SDK ||  { __namesp ace: true  };        
19   SDK.Metada ta = SDK.M etadata ||  { __names pace: true  };        
20          
21   (function  () {        
22          
23          
24    this.Retr ieveAllEnt ities = fu nction (En tityFilter s, Retriev eAsIfPubli shed, succ essCallBac k, errorCa llBack, pa ssThroughO bject) {        
25     ///<summ ary>        
26     /// Send s an async hronous Re trieveAllE ntities Re quest to r etrieve al l entities  in the sy stem        
27     ///</sum mary>        
28     ///<retu rns>entity MetadataCo llection</ returns>        
29     ///<para m name="En tityFilter s" type="N umber">        
30     /// SDK. Metadata.E ntityFilte rs provide s an enume ration for  the filte rs availab le to filt er which d ata is ret rieved.        
31     /// Incl ude only t hose eleme nts of the  entity yo u want to  retrieve.  Retrieving  all parts  of all en titities m ay take si gnificant  time.        
32     ///</par am>        
33     ///<para m name="Re trieveAsIf Published"  type="Boo lean">        
34     /// Sets  whether t o retrieve  the metad ata that h as not bee n publishe d.        
35     ///</par am>        
36     ///<para m name="su ccessCallB ack" type= "Function" >        
37     /// The  function t hat will b e passed t hrough and  be called  by a succ essful res ponse.        
38     /// This  function  must accep t the enti tyMetadata Collection  as a para meter.        
39     ///</par am>        
40     ///<para m name="er rorCallBac k" type="F unction">        
41     /// The  function t hat will b e passed t hrough and  be called  by a fail ed respons e.        
42     /// This  function  must accep t an Error  object as  a paramet er.        
43     ///</par am>        
44     ///<para m name="pa ssThroughO bject" opt ional="tru e"  type=" Object">        
45     /// An O bject that  will be p assed thro ugh to as  the second  parameter  to the su ccessCallB ack.        
46     ///</par am>        
47     if ((typ eof Entity Filters !=  "number")  || (Entit yFilters <  1 || Enti tyFilters  > 15))        
48     { throw  new Error( "SDK.Metad ata.Retrie veAllEntit ies Entity Filters mu st be a SD K.Metadata .EntityFil ters value ."); }        
49     if (type of Retriev eAsIfPubli shed != "b oolean")        
50     { throw  new Error( "SDK.Metad ata.Retrie veAllEntit ies Retrie veAsIfPubl ished must  be a bool ean value. "); }        
51     if (type of success CallBack ! = "functio n")        
52     { throw  new Error( "SDK.Metad ata.Retrie veAllEntit ies succes sCallBack  must be a  function." ); }        
53     if (type of errorCa llBack !=  "function" )        
54     { throw  new Error( "SDK.Metad ata.Retrie veAllEntit ies errorC allBack mu st be a fu nction.");  }        
55          
56     var enti tyFiltersV alue = _ev aluateEnti tyFilters( EntityFilt ers);        
57          
58     var requ est = [        
59     "<soapen v:Envelope  xmlns:soa penv=\"htt p://schema s.xmlsoap. org/soap/e nvelope/\" >",        
60       //Allo ws retriev al if Imag eAttribute Metadata o bjects        
61     "<soapen v:Header>< a:SdkClien tVersion x mlns:a=\"h ttp://sche mas.micros oft.com/xr m/2011/Con tracts\">7 .0</a:SdkC lientVersi on></soape nv:Header> ",        
62      "<soape nv:Body>",        
63       "<Exec ute xmlns= \"http://s chemas.mic rosoft.com /xrm/2011/ Contracts/ Services\"  xmlns:i=\ "http://ww w.w3.org/2 001/XMLSch ema-instan ce\">",        
64        "<req uest i:typ e=\"a:Retr ieveAllEnt itiesReque st\" xmlns :a=\"http: //schemas. microsoft. com/xrm/20 11/Contrac ts\">",        
65         "<a: Parameters  xmlns:b=\ "http://sc hemas.data contract.o rg/2004/07 /System.Co llections. Generic\"> ",        
66          "<a :KeyValueP airOfstrin ganyType>" ,        
67           "< b:key>Enti tyFilters< /b:key>",        
68           "< b:value i: type=\"c:E ntityFilte rs\" xmlns :c=\"http: //schemas. microsoft. com/xrm/20 11/Metadat a\">" + _x mlEncode(e ntityFilte rsValue) +  "</b:valu e>",        
69          "</ a:KeyValue PairOfstri nganyType> ",        
70          "<a :KeyValueP airOfstrin ganyType>" ,        
71           "< b:key>Retr ieveAsIfPu blished</b :key>",        
72           "< b:value i: type=\"c:b oolean\" x mlns:c=\"h ttp://www. w3.org/200 1/XMLSchem a\">" + _x mlEncode(R etrieveAsI fPublished .toString( )) + "</b: value>",        
73          "</ a:KeyValue PairOfstri nganyType> ",        
74         "</a :Parameter s>",        
75         "<a: RequestId  i:nil=\"tr ue\" />",        
76         "<a: RequestNam e>Retrieve AllEntitie s</a:Reque stName>",        
77       "</req uest>",        
78      "</Exec ute>",        
79     "</soape nv:Body>",        
80     "</soape nv:Envelop e>"].join( "");        
81     var req  = new XMLH ttpRequest ();        
82     req.open ("POST", _ getUrl() +  "/XRMServ ices/2011/ Organizati on.svc/web ", true);        
83     try { re q.response Type = 'ms xml-docume nt'} catch (e){}        
84     req.setR equestHead er("Accept ", "applic ation/xml,  text/xml,  */*");        
85     req.setR equestHead er("Conten t-Type", " text/xml;  charset=ut f-8");        
86     req.setR equestHead er("SOAPAc tion", "ht tp://schem as.microso ft.com/xrm /2011/Cont racts/Serv ices/IOrga nizationSe rvice/Exec ute");        
87     req.onre adystatech ange = fun ction () {        
88      if (req .readyStat e == 4 /*  complete * /) {        
89      req.onr eadystatec hange = nu ll; //Addr esses pote ntial memo ry leak is sue with I E        
90       if (re q.status = = 200) {        
91        //Suc cess                                    
92        var d oc = req.r esponseXML ;        
93        try{_ setSelecti onNamespac es(doc);}c atch(e){}        
94        var e ntityMetad ataNodes =  _selectNo des(doc, " //c:Entity Metadata") ;        
95        var e ntityMetad ataCollect ion = [];        
96        for ( var i = 0;  i < entit yMetadataN odes.lengt h; i++) {        
97         var  a = _objec tifyNode(e ntityMetad ataNodes[i ]);        
98         a._t ype = "Ent ityMetadat a";        
99         enti tyMetadata Collection .push(a);        
100        }        
101          
102        succe ssCallBack (entityMet adataColle ction, pas sThroughOb ject);        
103       }        
104       else {        
105        error CallBack(_ getError(r eq));        
106       }        
107      }        
108     };        
109     req.send (request);        
110          
111    };        
112          
113    this.Retr ieveEntity  = functio n (EntityF ilters, Lo gicalName,  MetadataI d, Retriev eAsIfPubli shed, succ essCallBac k, errorCa llBack, pa ssThroughO bject) {        
114     ///<summ ary>        
115     /// Send s an async hronous Re trieveEnti ty Request  to retrie ve a speci fic entity        
116     ///</sum mary>        
117     ///<retu rns>entity Metadata</ returns>        
118     ///<para m name="En tityFilter s" type="N umber">        
119     /// SDK. Metadata.E ntityFilte rs provide s an enume ration for  the filte rs availab le to filt er which d ata is ret rieved.        
120     /// Incl ude only t hose eleme nts of the  entity yo u want to  retrieve.  Retrieving  all parts  of all en titities m ay take si gnificant  time.        
121     ///</par am>        
122     ///<para m name="Lo gicalName"  optional= "true" typ e="String" >        
123     /// The  logical na me of the  entity req uested. A  null value  may be us ed if a Me tadataId i s provided .        
124     ///</par am>        
125     ///<para m name="Me tadataId"  optional=" true" type ="String">        
126     /// A nu ll value o r an empty  guid may  be passed  if a Logic alName is  provided.        
127     ///</par am>        
128     ///<para m name="Re trieveAsIf Published"  type="Boo lean">        
129     /// Sets  whether t o retrieve  the metad ata that h as not bee n publishe d.        
130     ///</par am>        
131     ///<para m name="su ccessCallB ack" type= "Function" >        
132     /// The  function t hat will b e passed t hrough and  be called  by a succ essful res ponse.        
133     /// This  function  must accep t the enti tyMetadata  as a para meter.        
134     ///</par am>        
135     ///<para m name="er rorCallBac k" type="F unction">        
136     /// The  function t hat will b e passed t hrough and  be called  by a fail ed respons e.        
137     /// This  function  must accep t an Error  object as  a paramet er.        
138     ///</par am>        
139     ///<para m name="pa ssThroughO bject" opt ional="tru e"  type=" Object">        
140     /// An O bject that  will be p assed thro ugh to as  the second  parameter  to the su ccessCallB ack.        
141     ///</par am>        
142     if ((typ eof Entity Filters !=  "number")  || (Entit yFilters <  1 || Enti tyFilters  > 15))        
143     { throw  new Error( "SDK.Metad ata.Retrie veEntity E ntityFilte rs must be  a SDK.Met adata.Enti tyFilters  value.");  }        
144     if (Logi calName ==  null && M etadataId  == null) {        
145      throw n ew Error(" SDK.Metada ta.Retriev eEntity re quires eit her the Lo gicalName  or Metadat aId parame ter not be  null.");        
146     }        
147     if (Logi calName !=  null) {        
148      if (typ eof Logica lName != " string")        
149      { throw  new Error ("SDK.Meta data.Retri eveEntity  LogicalNam e must be  a string v alue."); }        
150      Metadat aId = "000 00000-0000 -0000-0000 -000000000 000";        
151     }        
152     if (Meta dataId !=  null && Lo gicalName  == null) {        
153      if (typ eof Metada taId != "s tring")        
154      { throw  new Error ("SDK.Meta data.Retri eveEntity  MetadataId  must be a  string va lue."); }        
155     }        
156     if (type of Retriev eAsIfPubli shed != "b oolean")        
157     { throw  new Error( "SDK.Metad ata.Retrie veEntity R etrieveAsI fPublished  must be a  boolean v alue."); }        
158     if (type of success CallBack ! = "functio n")        
159     { throw  new Error( "SDK.Metad ata.Retrie veEntity s uccessCall Back must  be a funct ion."); }        
160     if (type of errorCa llBack !=  "function" )        
161     { throw  new Error( "SDK.Metad ata.Retrie veEntity e rrorCallBa ck must be  a functio n."); }        
162     var enti tyFiltersV alue = _ev aluateEnti tyFilters( EntityFilt ers);        
163          
164     var enti tyLogicalN ameValueNo de = "";        
165     if (Logi calName ==  null)        
166     { entity LogicalNam eValueNode  = "<b:val ue i:nil=\ "true\" /> "; }        
167     else        
168     { entity LogicalNam eValueNode  = "<b:val ue i:type= \"c:string \"   xmlns :c=\"http: //www.w3.o rg/2001/XM LSchema\"> " + _xmlEn code(Logic alName.toL owerCase() ) + "</b:v alue>"; }        
169     var requ est = [        
170     "<soapen v:Envelope  xmlns:soa penv=\"htt p://schema s.xmlsoap. org/soap/e nvelope/\" >",        
171       //Allo ws retriev al if Imag eAttribute Metadata o bjects        
172     "<soapen v:Header>< a:SdkClien tVersion x mlns:a=\"h ttp://sche mas.micros oft.com/xr m/2011/Con tracts\">6 .0</a:SdkC lientVersi on></soape nv:Header> ",        
173      "<soape nv:Body>",        
174       "<Exec ute xmlns= \"http://s chemas.mic rosoft.com /xrm/2011/ Contracts/ Services\"  xmlns:i=\ "http://ww w.w3.org/2 001/XMLSch ema-instan ce\">",        
175        "<req uest i:typ e=\"a:Retr ieveEntity Request\"  xmlns:a=\" http://sch emas.micro soft.com/x rm/2011/Co ntracts\"> ",        
176         "<a: Parameters  xmlns:b=\ "http://sc hemas.data contract.o rg/2004/07 /System.Co llections. Generic\"> ",        
177          "<a :KeyValueP airOfstrin ganyType>" ,        
178           "< b:key>Enti tyFilters< /b:key>",        
179           "< b:value i: type=\"c:E ntityFilte rs\" xmlns :c=\"http: //schemas. microsoft. com/xrm/20 11/Metadat a\">" + _x mlEncode(e ntityFilte rsValue) +  "</b:valu e>",        
180          "</ a:KeyValue PairOfstri nganyType> ",        
181          "<a :KeyValueP airOfstrin ganyType>" ,        
182           "< b:key>Meta dataId</b: key>",        
183           "< b:value i: type=\"ser :guid\"  x mlns:ser=\ "http://sc hemas.micr osoft.com/ 2003/10/Se rializatio n/\">" + _ xmlEncode( MetadataId ) + "</b:v alue>",        
184          "</ a:KeyValue PairOfstri nganyType> ",        
185          "<a :KeyValueP airOfstrin ganyType>" ,        
186           "< b:key>Retr ieveAsIfPu blished</b :key>",        
187           "< b:value i: type=\"c:b oolean\" x mlns:c=\"h ttp://www. w3.org/200 1/XMLSchem a\">" + _x mlEncode(R etrieveAsI fPublished .toString( )) + "</b: value>",        
188          "</ a:KeyValue PairOfstri nganyType> ",        
189          "<a :KeyValueP airOfstrin ganyType>" ,        
190           "< b:key>Logi calName</b :key>",        
191            e ntityLogic alNameValu eNode,        
192          "</ a:KeyValue PairOfstri nganyType> ",        
193         "</a :Parameter s>",        
194         "<a: RequestId  i:nil=\"tr ue\" />",        
195         "<a: RequestNam e>Retrieve Entity</a: RequestNam e>",        
196        "</re quest>",        
197       "</Exe cute>",        
198      "</soap env:Body>" ,        
199     "</soape nv:Envelop e>"].join( "");        
200     var req  = new XMLH ttpRequest ();        
201     req.open ("POST", _ getUrl() +  "/XRMServ ices/2011/ Organizati on.svc/web ", true);        
202     try { re q.response Type = 'ms xml-docume nt'} catch (e){}        
203     req.setR equestHead er("Accept ", "applic ation/xml,  text/xml,  */*");        
204     req.setR equestHead er("Conten t-Type", " text/xml;  charset=ut f-8");        
205     req.setR equestHead er("SOAPAc tion", "ht tp://schem as.microso ft.com/xrm /2011/Cont racts/Serv ices/IOrga nizationSe rvice/Exec ute");        
206     req.onre adystatech ange = fun ction () {        
207      if (req .readyStat e == 4 /*  complete * /) {        
208      req.onr eadystatec hange = nu ll; //Addr esses pote ntial memo ry leak is sue with I E        
209       if (re q.status = = 200) {        
210        var d oc = req.r esponseXML ;        
211        try{_ setSelecti onNamespac es(doc);}c atch(e){}        
212        var a  = _object ifyNode(_s electSingl eNode(doc,  "//b:valu e"));        
213        a._ty pe = "Enti tyMetadata ";        
214        succe ssCallBack (a, passTh roughObjec t);        
215       }        
216       else {        
217        //Fai lure        
218        error CallBack(_ getError(r eq));        
219       }        
220      }        
221          
222     };        
223     req.send (request);        
224          
225          
226    };        
227          
228    this.Retr ieveAttrib ute = func tion (Enti tyLogicalN ame, Logic alName, Me tadataId,  RetrieveAs IfPublishe d, success CallBack,  errorCallB ack, passT hroughObje ct) {        
229     ///<summ ary>        
230     /// Send s an async hronous Re trieveAttr ibute Requ est to ret rieve a sp ecific ent ity        
231     ///</sum mary>        
232     ///<retu rns>Attrib uteMetadat a</returns >        
233     ///<para m name="En tityLogica lName"  op tional="tr ue" type=" String">        
234     /// The  logical na me of the  entity for  the attri bute reque sted. A nu ll value m ay be used  if a Meta dataId is  provided.        
235     ///</par am>        
236     ///<para m name="Lo gicalName"  optional= "true" typ e="String" >        
237     /// The  logical na me of the  attribute  requested.          
238     ///</par am>        
239     ///<para m name="Me tadataId"  optional=" true" type ="String">        
240     /// A nu ll value m ay be pass ed if an E ntityLogic alName and  LogicalNa me is prov ided.        
241     ///</par am>        
242     ///<para m name="Re trieveAsIf Published"  type="Boo lean">        
243     /// Sets  whether t o retrieve  the metad ata that h as not bee n publishe d.        
244     ///</par am>        
245     ///<para m name="su ccessCallB ack" type= "Function" >        
246     /// The  function t hat will b e passed t hrough and  be called  by a succ essful res ponse.        
247     /// This  function  must accep t the enti tyMetadata  as a para meter.        
248     ///</par am>        
249     ///<para m name="er rorCallBac k" type="F unction">        
250     /// The  function t hat will b e passed t hrough and  be called  by a fail ed respons e.        
251     /// This  function  must accep t an Error  object as  a paramet er.        
252     ///</par am>        
253     ///<para m name="pa ssThroughO bject" opt ional="tru e"  type=" Object">        
254     /// An O bject that  will be p assed thro ugh to as  the second  parameter  to the su ccessCallB ack.        
255     ///</par am>        
256     if (Enti tyLogicalN ame == nul l && Logic alName ==  null && Me tadataId = = null) {        
257      throw n ew Error(" SDK.Metada ta.Retriev eAttribute  requires  either the  EntityLog icalName a nd Logical Name  para meters or  the Metada taId param eter not b e null.");        
258     }        
259     if (Meta dataId !=  null && En tityLogica lName == n ull && Log icalName = = null) {        
260      if (typ eof Metada taId != "s tring")        
261      { throw  new Error ("SDK.Meta data.Retri eveEntity  MetadataId  must be a  string va lue."); }        
262     }        
263     else        
264     { Metada taId = "00 000000-000 0-0000-000 0-00000000 0000"; }        
265     if (Enti tyLogicalN ame != nul l) {        
266      if (typ eof Entity LogicalNam e != "stri ng") {        
267       { thro w new Erro r("SDK.Met adata.Retr ieveAttrib ute Entity LogicalNam e must be  a string v alue."); }        
268      }        
269     }        
270     if (Logi calName !=  null) {        
271      if (typ eof Logica lName != " string") {        
272       { thro w new Erro r("SDK.Met adata.Retr ieveAttrib ute Logica lName must  be a stri ng value." ); }        
273      }        
274          
275     }        
276     if (type of Retriev eAsIfPubli shed != "b oolean")        
277     { throw  new Error( "SDK.Metad ata.Retrie veAttribut e Retrieve AsIfPublis hed must b e a boolea n value.") ; }        
278     if (type of success CallBack ! = "functio n")        
279     { throw  new Error( "SDK.Metad ata.Retrie veAttribut e successC allBack mu st be a fu nction.");  }        
280     if (type of errorCa llBack !=  "function" )        
281     { throw  new Error( "SDK.Metad ata.Retrie veAttribut e errorCal lBack must  be a func tion."); }        
282          
283     var enti tyLogicalN ameValueNo de;        
284     if (Enti tyLogicalN ame == nul l) {        
285      entityL ogicalName ValueNode  = "<b:valu e i:nil=\" true\" />" ;        
286     }        
287     else {        
288      entityL ogicalName ValueNode  = "<b:valu e i:type=\ "c:string\ " xmlns:c= \"http://w ww.w3.org/ 2001/XMLSc hema\">" +  _xmlEncod e(EntityLo gicalName. toLowerCas e()) + "</ b:value>";        
289     }        
290     var logi calNameVal ueNode;        
291     if (Logi calName ==  null) {        
292      logical NameValueN ode = "<b: value i:ni l=\"true\"  />";        
293     }        
294     else {        
295      logical NameValueN ode = "<b: value i:ty pe=\"c:str ing\"   xm lns:c=\"ht tp://www.w 3.org/2001 /XMLSchema \">" + _xm lEncode(Lo gicalName. toLowerCas e()) + "</ b:value>";        
296     }        
297     var requ est = [        
298     "<soapen v:Envelope  xmlns:soa penv=\"htt p://schema s.xmlsoap. org/soap/e nvelope/\" >",        
299     //Allows  retrieval  if ImageA ttributeMe tadata obj ects        
300     "<soapen v:Header>< a:SdkClien tVersion x mlns:a=\"h ttp://sche mas.micros oft.com/xr m/2011/Con tracts\">6 .0</a:SdkC lientVersi on></soape nv:Header> ",        
301      "<soape nv:Body>",        
302       "<Exec ute xmlns= \"http://s chemas.mic rosoft.com /xrm/2011/ Contracts/ Services\"  xmlns:i=\ "http://ww w.w3.org/2 001/XMLSch ema-instan ce\">",        
303        "<req uest i:typ e=\"a:Retr ieveAttrib uteRequest \" xmlns:a =\"http:// schemas.mi crosoft.co m/xrm/2011 /Contracts \">",        
304         "<a: Parameters  xmlns:b=\ "http://sc hemas.data contract.o rg/2004/07 /System.Co llections. Generic\"> ",        
305          "<a :KeyValueP airOfstrin ganyType>" ,        
306           "< b:key>Enti tyLogicalN ame</b:key >",        
307            e ntityLogic alNameValu eNode,        
308          "</ a:KeyValue PairOfstri nganyType> ",        
309          "<a :KeyValueP airOfstrin ganyType>" ,        
310           "< b:key>Meta dataId</b: key>",        
311           "< b:value i: type=\"ser :guid\"  x mlns:ser=\ "http://sc hemas.micr osoft.com/ 2003/10/Se rializatio n/\">" + _ xmlEncode( MetadataId ) + "</b:v alue>",        
312          "</ a:KeyValue PairOfstri nganyType> ",        
313           "< a:KeyValue PairOfstri nganyType> ",        
314           "< b:key>Retr ieveAsIfPu blished</b :key>",        
315         "<b: value i:ty pe=\"c:boo lean\" xml ns:c=\"htt p://www.w3 .org/2001/ XMLSchema\ ">" + _xml Encode(Ret rieveAsIfP ublished.t oString())  + "</b:va lue>",        
316          "</ a:KeyValue PairOfstri nganyType> ",        
317          "<a :KeyValueP airOfstrin ganyType>" ,        
318           "< b:key>Logi calName</b :key>",        
319            l ogicalName ValueNode,        
320          "</ a:KeyValue PairOfstri nganyType> ",        
321         "</a :Parameter s>",        
322         "<a: RequestId  i:nil=\"tr ue\" />",        
323         "<a: RequestNam e>Retrieve Attribute< /a:Request Name>",        
324        "</re quest>",        
325       "</Exe cute>",        
326      "</soap env:Body>" ,        
327     "</soape nv:Envelop e>"].join( "");        
328     var req  = new XMLH ttpRequest ();        
329     req.open ("POST", _ getUrl() +  "/XRMServ ices/2011/ Organizati on.svc/web ", true);        
330         try  { req.resp onseType =  'msxml-do cument'} c atch(e){}        
331     req.setR equestHead er("Accept ", "applic ation/xml,  text/xml,  */*");        
332     req.setR equestHead er("Conten t-Type", " text/xml;  charset=ut f-8");        
333     req.setR equestHead er("SOAPAc tion", "ht tp://schem as.microso ft.com/xrm /2011/Cont racts/Serv ices/IOrga nizationSe rvice/Exec ute");        
334     req.onre adystatech ange = fun ction () {        
335      if (req .readyStat e == 4 /*  complete * /) {        
336      req.onr eadystatec hange = nu ll; //Addr esses pote ntial memo ry leak is sue with I E        
337       if (re q.status = = 200) {        
338        //Suc cess        
339        var d oc = req.r esponseXML ;        
340        try{_ setSelecti onNamespac es(doc);}c atch(e){}        
341        var a  = _object ifyNode(_s electSingl eNode(doc,  "//b:valu e"));        
342                                              
343        succe ssCallBack (a, passTh roughObjec t);        
344       }        
345       else {        
346        //Fai lure        
347        error CallBack(_ getError(r eq));        
348       }        
349      }        
350     };        
351     req.send (request);        
352          
353          
354    };        
355          
356    this.Enti tyFilters  = function  () {        
357     /// <sum mary>SDK.M etadata.En tityFilter s enum sum mary</summ ary>        
358     /// <fie ld name="D efault" ty pe="Number " static=" true">enum  field sum mary for D efault</fi eld>        
359     /// <fie ld name="E ntity" typ e="Number"  static="t rue">enum  field summ ary for En tity</fiel d>        
360     /// <fie ld name="A ttributes"  type="Num ber" stati c="true">e num field  summary fo r Attribut es</field>        
361     /// <fie ld name="P rivileges"  type="Num ber" stati c="true">e num field  summary fo r Privileg es</field>        
362     /// <fie ld name="R elationshi ps" type=" Number" st atic="true ">enum fie ld summary  for Relat ionships</ field>        
363     /// <fie ld name="A ll" type=" Number" st atic="true ">enum fie ld summary  for All</ field>        
364     throw ne w Error("C onstructor  not imple mented thi s is a sta tic enum." );        
365    };        
366          
367          
368          
369    var _arra yElements  = ["Attrib utes",        
370     "ManyToM anyRelatio nships",        
371     "ManyToO neRelation ships",        
372     "OneToMa nyRelation ships",        
373     "Privile ges",        
374     "Localiz edLabels",        
375     "Options ",        
376     "Targets "];        
377          
378     function  _getError (resp) {        
379     ///<summ ary>        
380     /// Priv ate functi on that at tempts to  parse erro rs related  to connec tivity or  WCF faults .        
381     ///</sum mary>        
382     ///<para m name="re sp" type=" XMLHttpReq uest">        
383     /// The  XMLHttpReq uest repre senting fa iled respo nse.        
384     ///</par am>        
385          
386     //Error  descriptio ns come fr om http:// support.mi crosoft.co m/kb/19362 5        
387     if (resp .status ==  12029)        
388     { return  new Error ("The atte mpt to con nect to th e server f ailed.");  }        
389     if (resp .status ==  12007)        
390     { return  new Error ("The serv er name co uld not be  resolved. "); }        
391     var faul tXml = res p.response XML;        
392     var erro rMessage =  "Unknown  (unable to  parse the  fault)";        
393     if (type of faultXm l == "obje ct") {        
394          
395      var fau ltstring =  null;        
396      var Err orCode = n ull;        
397          
398      var bod yNode = fa ultXml.fir stChild.fi rstChild;        
399          
400      //Retri eve the fa ult node        
401      for (va r i = 0; i  < bodyNod e.childNod es.length;  i++) {        
402       var no de = bodyN ode.childN odes[i];        
403          
404       //NOTE : This com parison do es not han dle the ca se where t he XML nam espace cha nges        
405       if ("s :Fault" ==  node.node Name) {        
406        for ( var j = 0;  j < node. childNodes .length; j ++) {        
407         var  testNode =  node.chil dNodes[j];        
408         if ( "faultstri ng" == tes tNode.node Name) {        
409          fau ltstring =  _getNodeT ext(testNo de);        
410         }        
411         if ( "detail" = = testNode .nodeName)  {        
412          for  (var k =  0; k < tes tNode.chil dNodes.len gth; k++)  {        
413           va r orgServi ceFault =  testNode.c hildNodes[ k];        
414           if  ("Organiz ationServi ceFault" = = orgServi ceFault.no deName) {        
415            f or (var l  = 0; l < o rgServiceF ault.child Nodes.leng th; l++) {        
416              var ErrorC odeNode =  orgService Fault.chil dNodes[l];        
417              if ("Error Code" == E rrorCodeNo de.nodeNam e) {        
418               ErrorCode  = _getNod eText(Erro rCodeNode) ;        
419               break;        
420              }        
421            }        
422           }        
423          }        
424          
425         }        
426        }        
427        break ;        
428       }        
429          
430      }        
431     }        
432     if (Erro rCode != n ull && fau ltstring ! = null) {        
433      errorMe ssage = "E rror Code: " + ErrorC ode + " Me ssage: " +  faultstri ng;        
434     }        
435     else {        
436      if (fau ltstring ! = null) {        
437       errorM essage = f aultstring ;        
438      }        
439     }        
440     return n ew Error(e rrorMessag e);        
441    };        
442          
443    function  _Context()  {        
444     var erro rMessage =  "Context  is not ava ilable.";        
445     if (type of GetGlob alContext  != "undefi ned")        
446     { return  GetGlobal Context();  }        
447     else {        
448      if (typ eof Xrm !=  "undefine d") {        
449       return  Xrm.Page. context;        
450      }        
451      else        
452      { retur n new Erro r(errorMes sage); }        
453     }        
454    };        
455          
456    function  _getUrl()  {        
457        var u rl = _Cont ext().getC lientUrl() ;        
458     return u rl;        
459    };        
460          
461    function  _evaluateE ntityFilte rs(EntityF ilters) {        
462     var enti tyFilterAr ray = [];        
463     if ((1 &  EntityFil ters) == 1 ) {        
464      entityF ilterArray .push("Ent ity");        
465     }        
466     if ((2 &  EntityFil ters) == 2 ) {        
467      entityF ilterArray .push("Att ributes");        
468     }        
469     if ((4 &  EntityFil ters) == 4 ) {        
470      entityF ilterArray .push("Pri vileges");        
471     }        
472     if ((8 &  EntityFil ters) == 8 ) {        
473      entityF ilterArray .push("Rel ationships ");        
474     }        
475     return e ntityFilte rArray.joi n(" ");        
476    };        
477          
478    function  _isMetadat aArray(ele mentName)  {        
479     for (var  i = 0; i  < _arrayEl ements.len gth; i++)  {        
480      if (ele mentName = = _arrayEl ements[i])  {        
481       return  true;        
482      }        
483     }        
484     return f alse;        
485    };        
486          
487    function  _objectify Node(node)  {        
488     //Check  for null        
489     if (node .attribute s != null  && node.at tributes.l ength == 1 ) {        
490      if (nod e.attribut es.getName dItem("i:n il") != nu ll && node .attribute s.getNamed Item("i:ni l").nodeVa lue == "tr ue") {        
491       return  null;        
492      }        
493     }        
494          
495     //Check  if it is a  value        
496     if ((nod e.firstChi ld != null ) && (node .firstChil d.nodeType  == 3)) {        
497      var nod eName = _g etNodeName (node);        
498          
499      switch  (nodeName)  {        
500       //Inte ger Values          
501       case " ActivityTy peMask":        
502       case " ObjectType Code":        
503       case " ColumnNumb er":        
504       case " DefaultFor mValue":        
505       case " MaxValue":        
506       case " MinValue":        
507       case " MaxLength" :        
508       case " Order":        
509       case " Precision" :        
510       case " PrecisionS ource":        
511       case " LanguageCo de":        
512        retur n parseInt (node.firs tChild.nod eValue, 10 );        
513        // Bo olean valu es        
514       case " AutoRouteT oOwnerQueu e":        
515       case " CanBeChang ed":        
516       case " CanTrigger Workflow":        
517       case " IsActivity ":        
518       case " IsAIRUpdat ed":        
519       case " IsActivity Party":        
520       case " IsAvailabl eOffline":        
521       case " IsChildEnt ity":        
522       case " IsCustomEn tity":        
523       case " IsCustomOp tionSet":            
524       case " IsDocument Management Enabled":        
525       case " IsEnabledF orCharts":        
526       case " IsGlobal":        
527       case " IsImportab le":        
528       case " IsIntersec t":        
529       case " IsManaged" :        
530       case " IsReadingP aneEnabled ":        
531       case " IsValidFor AdvancedFi nd":        
532       case " CanBeSecur edForCreat e":        
533       case " CanBeSecur edForRead" :        
534       case " CanBeSecur edForUpdat e":        
535       case " IsCustomAt tribute":        
536       case " IsManaged" :        
537       case " IsPrimaryI d":        
538       case " IsPrimaryN ame":        
539       case " IsSecured" :        
540       case " IsValidFor Create":        
541       case " IsValidFor Read":        
542       case " IsValidFor Update":        
543       case " IsCustomRe lationship ":        
544       case " CanBeBasic ":        
545       case " CanBeDeep" :        
546       case " CanBeGloba l":        
547       case " CanBeLocal ":        
548        retur n (node.fi rstChild.n odeValue = = "true")  ? true : f alse;        
549        //Opt ionMetadat a.Value an d BooleanM anagedProp erty.Value  and Attri buteRequir edLevelMan agedProper ty.Value        
550       case " Value":        
551        //Boo leanManage dProperty. Value        
552        if (( node.first Child.node Value == " true") ||  (node.firs tChild.nod eValue ==  "false"))  {        
553         retu rn (node.f irstChild. nodeValue  == "true")  ? true :  false;        
554        }        
555        //Att ributeRequ iredLevelM anagedProp erty.Value        
556        if (        
557     (node.fi rstChild.n odeValue = = "Applica tionRequir ed") ||        
558     (node.fi rstChild.n odeValue = = "None")  ||        
559     (node.fi rstChild.n odeValue = = "Recomme nded") ||        
560     (node.fi rstChild.n odeValue = = "SystemR equired")        
561     ) {        
562         retu rn node.fi rstChild.n odeValue;        
563        }        
564        var n umberValue  = parseIn t(node.fir stChild.no deValue, 1 0);        
565        if (i sNaN(numbe rValue)) {        
566            / /FormatNam e.Value        
567            r eturn node .firstChil d.nodeValu e;        
568        }        
569        else  {        
570            / /OptionMet adata.Valu e        
571            r eturn numb erValue;        
572        }        
573        break ;        
574       //Stri ng values         
575       defaul t:        
576        retur n node.fir stChild.no deValue;        
577      }        
578          
579     }        
580          
581     //Check  if it is a  known arr ay        
582     if (_isM etadataArr ay(_getNod eName(node ))) {        
583      var arr ayValue =  [];        
584          
585      for (va r i = 0; i  < node.ch ildNodes.l ength; i++ ) {        
586       var ob jectTypeNa me;        
587       if ((n ode.childN odes[i].at tributes ! = null) &&  (node.chi ldNodes[i] .attribute s.getNamed Item("i:ty pe") != nu ll)) {        
588        objec tTypeName  = node.chi ldNodes[i] .attribute s.getNamed Item("i:ty pe").nodeV alue.split (":")[1];        
589       }        
590       else {        
591          
592        objec tTypeName  = _getNode Name(node. childNodes [i]);        
593       }        
594          
595       var b  = _objecti fyNode(nod e.childNod es[i]);        
596       b._typ e = object TypeName;        
597       arrayV alue.push( b);        
598          
599      }        
600          
601      return  arrayValue ;        
602     }        
603          
604       //Null  entity de scription  labels are  returned  as <label/ > - not us ing i:nil  = true;        
605     if(node. childNodes .length ==  0)        
606     {        
607     return n ull;        
608     }        
609          
610     //Otherw ise return  an object        
611     var c =  {};        
612     if (node .attribute s.getNamed Item("i:ty pe") != nu ll) {        
613      c._type  = node.at tributes.g etNamedIte m("i:type" ).nodeValu e.split(": ")[1];        
614     }        
615     for (var  i = 0; i  < node.chi ldNodes.le ngth; i++)  {        
616      if (nod e.childNod es[i].node Type == 3)  {        
617       c[_get NodeName(n ode.childN odes[i])]  = node.chi ldNodes[i] .nodeValue ;        
618      }        
619      else {        
620       c[_get NodeName(n ode.childN odes[i])]  = _objecti fyNode(nod e.childNod es[i]);        
621      }        
622          
623     }        
624     return c ;        
625    };        
626          
627    function  _selectNod es(node, X PathExpres sion) {        
628     if (type of (node.s electNodes ) != "unde fined") {        
629      return  node.selec tNodes(XPa thExpressi on);        
630     }        
631     else {        
632      var out put = [];        
633      var XPa thResults  = node.eva luate(XPat hExpressio n, node, _ NSResolver , XPathRes ult.ANY_TY PE, null);        
634      var res ult = XPat hResults.i terateNext ();        
635      while ( result) {        
636       output .push(resu lt);        
637       result  = XPathRe sults.iter ateNext();        
638      }        
639      return  output;        
640     }        
641    };        
642          
643    function  _selectSin gleNode(no de, xpathE xpr) {        
644     if (type of (node.s electSingl eNode) !=  "undefined ") {        
645      return  node.selec tSingleNod e(xpathExp r);        
646     }        
647     else {        
648      var xpe  = new XPa thEvaluato r();        
649      var xPa thNode = x pe.evaluat e(xpathExp r, node, _ NSResolver , XPathRes ult.FIRST_ ORDERED_NO DE_TYPE, n ull);        
650      return  (xPathNode  != null)  ? xPathNod e.singleNo deValue :  null;        
651     }        
652    };        
653          
654    function  _selectSin gleNodeTex t(node, xp athExpr) {        
655     var x =  _selectSin gleNode(no de, xpathE xpr);        
656     if (_isN odeNull(x) )        
657     { return  null; }        
658     if (type of (x.text ) != "unde fined") {        
659      return  x.text;        
660     }        
661     else {        
662      return  x.textCont ent;        
663     }        
664    };        
665          
666    function  _getNodeTe xt(node) {        
667     if (type of (node.t ext) != "u ndefined")  {        
668      return  node.text;        
669     }        
670     else {        
671      return  node.textC ontent;        
672     }        
673    };        
674          
675    function  _isNodeNul l(node) {        
676     if (node  == null)        
677     { return  true; }        
678     if ((nod e.attribut es.getName dItem("i:n il") != nu ll) && (no de.attribu tes.getNam edItem("i: nil").valu e == "true "))        
679     { return  true; }        
680     return f alse;        
681    };        
682          
683    function  _getNodeNa me(node) {        
684     if (type of (node.b aseName) ! = "undefin ed") {        
685      return  node.baseN ame;        
686     }        
687     else {        
688      return  node.local Name;        
689     }        
690    };        
691          
692    function  _setSelect ionNamespa ces(doc)        
693    {        
694    var names paces = [        
695    "xmlns:s= 'http://sc hemas.xmls oap.org/so ap/envelop e/'",        
696    "xmlns:a= 'http://sc hemas.micr osoft.com/ xrm/2011/C ontracts'" ,        
697    "xmlns:i= 'http://ww w.w3.org/2 001/XMLSch ema-instan ce'",        
698    "xmlns:b= 'http://sc hemas.data contract.o rg/2004/07 /System.Co llections. Generic'",        
699    "xmlns:c= 'http://sc hemas.micr osoft.com/ xrm/2011/M etadata'"         
700    ];        
701    doc.setPr operty("Se lectionNam espaces",n amespaces. join(" ")) ;        
702            
703    }        
704          
705    function  _NSResolve r(prefix)  {        
706     var ns =  {        
707      "s": "h ttp://sche mas.xmlsoa p.org/soap /envelope/ ",        
708      "a": "h ttp://sche mas.micros oft.com/xr m/2011/Con tracts",        
709      "i": "h ttp://www. w3.org/200 1/XMLSchem a-instance ",        
710      "b": "h ttp://sche mas.dataco ntract.org /2004/07/S ystem.Coll ections.Ge neric",        
711      "c": "h ttp://sche mas.micros oft.com/xr m/2011/Met adata"        
712     };        
713     return n s[prefix]  || null;        
714    };        
715          
716    function  _xmlEncode (strInput)  {        
717     var c;        
718     var XmlE ncode = '' ;        
719     if (strI nput == nu ll) {        
720      return  null;        
721     }        
722     if (strI nput == '' ) {        
723      return  '';        
724     }        
725     for (var  cnt = 0;  cnt < strI nput.lengt h; cnt++)  {        
726      c = str Input.char CodeAt(cnt );        
727      if (((c  > 96) &&  (c < 123))  ||        
728                             ((c >  64) && (c  < 91)) ||        
729                             (c ==  32) ||        
730                             ((c >  47) && (c  < 58)) ||        
731                             (c ==  46) ||        
732                             (c ==  44) ||        
733                             (c ==  45) ||        
734                             (c ==  95)) {        
735       XmlEnc ode = XmlE ncode + St ring.fromC harCode(c) ;        
736      }        
737      else {        
738       XmlEnc ode = XmlE ncode + '& #' + c + ' ;';        
739      }        
740     }        
741     return X mlEncode;        
742    };        
743          
744   }).call(SD K.Metadata );        
745          
746   //SDK.Meta data.Entit yFilters        
747   // this en um is writ ten this w ay to enab le Visual  Studio Int elliSense        
748   SDK.Metada ta.EntityF ilters.pro totype = {        
749    Default:  1,        
750    Entity: 1 ,        
751    Attribute s: 2,        
752    Privilege s: 4,        
753    Relations hips: 8,        
754    All: 15        
755   };        
756   SDK.Metada ta.EntityF ilters.Def ault = 1;        
757   SDK.Metada ta.EntityF ilters.Ent ity = 1;        
758   SDK.Metada ta.EntityF ilters.Att ributes =  2;        
759   SDK.Metada ta.EntityF ilters.Pri vileges =  4;        
760   SDK.Metada ta.EntityF ilters.Rel ationships  = 8;        
761   SDK.Metada ta.EntityF ilters.All  = 15;        
762   SDK.Metada ta.EntityF ilters.__e num = true ;        
763   SDK.Metada ta.EntityF ilters.__f lags = tru e;        
764          
765          
766   //</snippe tSDK.Metad ata.js>        
767          
768