Produced by Araxis Merge on 12/4/2017 8:32:40 AM Central 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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | VCCM.zip\VCCM\CRM_solutions\VCCMResources\VCCMResources_3_0_0_12.zip\WebResources | ftp_VeteranJScriptpcmmjs395353A2-524D-E711-944F-0050568D743D | Mon Sep 18 10:55:52 2017 UTC |
| 2 | VCCM.zip\VCCM\CRM_solutions\VCCMResources\VCCMResources_3_0_0_12.zip\WebResources | ftp_VeteranJScriptpcmmjs395353A2-524D-E711-944F-0050568D743D | Thu Nov 30 17:22:14 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 1514 |
| Changed | 2 | 4 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| 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 |
No regular expressions were active.
| 1 | function p erformPCMM WebService Call(pFaci lityCode, pICN) { | |
| 2 | PC MMGridMemb ers = []; /*clear th e PCMMGrid Members ar ray before collectin g new data from PCMM */ | |
| 3 | // this funct ion is fir ed after r etrieving the vetera n's Prefer red Facili ty from ES R | |
| 4 | wr iteToConso le("begin performPCM MWebServic eCall()"); | |
| 5 | Xr m.Page.ui. clearFormN otificatio n("noPACTF romPCMM"); | |
| 6 | pc mm_Enabled = (_retri evedSettin gs.hasOwnP roperty("f tp_IsPCMME nabled") & & _retriev edSettings .ftp_IsPCM MEnabled ! = null) ? _retrieved Settings.f tp_IsPCMME nabled : t rue; | |
| 7 | wr iteToConso le("pcmm_E nabled: " + pcmm_Ena bled); | |
| 8 | if (pcmm_Enab led && _re trievedSet tings.hasO wnProperty ("ftp_Pati entSummary APIURL") & & !!_retri evedSettin gs.ftp_Pat ientSummar yAPIURL){ | |
| 9 | var facilityCo de = _notP rod ? "991 " : pFacil ityCode; | |
| 10 | writ eToConsole ("_notProd : " + _not Prod); | |
| 11 | writ eToConsole ("facility Code used in PCMM qu ery: " + f acilityCod e); | |
| 12 | var ICN = !!pI CN ? pICN : !!_ICN ? _ICN : nu ll; | |
| 13 | if(! !facilityC ode && !!I CN){ | |
| 14 | var pc mmUrl = _r etrievedSe ttings.ftp _DACURL + _retrieved Settings.f tp_Patient SummaryAPI URL + faci lityCode + "/" + ICN + "?idTyp e=ICN"; | |
| 15 | writeT oConsole(" firing GET against P CMM url: " + pcmmUrl ); | |
| 16 | $.ajax ({ | |
| 17 | type: "G ET", | |
| 18 | contentT ype: "appl ication/js on; charse t=utf-8", | |
| 19 | datatype : "json", | |
| 20 | url: pcm mUrl, | |
| 21 | beforeSe nd: functi on (XMLHtt pRequest) { | |
| 22 | //Specifyi ng this he ader ensur es that th e results will be re turned as JSON. | |
| 23 | XMLHttpReq uest.setRe questHeade r("Accept" , "applica tion/json" ); | |
| 24 | }, | |
| 25 | success: function (response, textStatu s, XmlHttp Request) { | |
| 26 | var return Object = r esponse; | |
| 27 | writeToCon sole("insi de PCMM su ccess call back"); | |
| 28 | //parse th e returnOb ject JSON object for data from PCMM. | |
| 29 | if (typeof returnObj ect != "un defined" & & $.isPlai nObject(re turnObject ) && !$.is EmptyObjec t(returnOb ject)) { | |
| 30 | if (!$.isXMLD oc(returnO bject)){ | |
| 31 | if ( returnObje ct.ErrorOc curred == true || re turnObject .ErrorMess age != nul l || retur nObject.De bugInfo != null) { | |
| 32 | writeT oConsole(" error retr ieving PCM M data:"); | |
| 33 | writeT oConsole(r eturnObjec t.DebugInf o); | |
| 34 | fillFt p_pactIdWi thPlacehol derPactTea m("Error o ccurred re trieving P CMM data f or facilit y: " + fac ilityCode + (_notPro d ? "(Non- Prod)" : " ")); | |
| 35 | } | |
| 36 | else { | |
| 37 | if (re turnObject .hasOwnPro perty("Dat a")) { | |
| 38 | var data = returnO bject.Data ; | |
| 39 | writeToC onsole("go t data obj ect from P CMM: "); | |
| 40 | writeToC onsole(dat a); | |
| 41 | var summ aryText = data.Patie ntSummaryT ext; | |
| 42 | if (data .hasOwnPro perty("pat ientAssign ments") && $.isArray (data.pati entAssignm ents) && d ata.patien tAssignmen ts.length > 0) { | |
| 43 | //this is the happy path | |
| 44 | var patien tAssignmen t = data.p atientAssi gnments[0] ; | |
| 45 | writeToCon sole("got patientAss ignment fr om data.") ; | |
| 46 | processPCH BAssignmen t(patientA ssignment) ; | |
| 47 | processMen talHealthP rovider(pa tientAssig nment); | |
| 48 | } | |
| 49 | else if (summaryTe xt.trim() == "No PAC T assigned at any VA location. ") { | |
| 50 | PCMMGridMe mbers.push ({ Name: s ummaryText .trim(), T eamRoleNam e: "" }); | |
| 51 | fillFtp_pa ctIdWithPl aceholderP actTeam("T his vetera n does not have a PA CT assigne d at any V A location s" + (_not Prod ? " ( Non-Prod)" : "")); | |
| 52 | return; | |
| 53 | } | |
| 54 | else if (summaryTe xt.trim() == "Patien t was not found for local site !") { | |
| 55 | PCMMGridMe mbers.push ({ Name: s ummaryText .trim(), T eamRoleNam e: "" }); | |
| 56 | fillFtp_pa ctIdWithPl aceholderP actTeam("P CMM did no t find vet eran at fa cility: " + facility Code + (_n otProd ? " (Non-Prod )" : "")); | |
| 57 | return; | |
| 58 | } | |
| 59 | else { | |
| 60 | //if we do n't find A NY patient Assignment s and also don't hav e a "no re sults mess age", just assign th e placehol der PACT t eam | |
| 61 | fillFtp_pa ctIdWithPl aceholderP actTeam("P CMM did no t return a ny data fo r veteran at facilit y: " + fac ilityCode + (_notPro d ? " (Non -Prod)" : "")); | |
| 62 | } | |
| 63 | } | |
| 64 | } | |
| 65 | } | |
| 66 | el se{ | |
| 67 | fill Ftp_pactId WithPlaceh olderPactT eam("PCMM returned d ata for ve teran at f acility " + facility Code + ", but it is in the wro ng format. \nCheck yo ur CRM org anization' s Active S ettings.") ; | |
| 68 | } | |
| 69 | } | |
| 70 | else { | |
| 71 | fi llFtp_pact IdWithPlac eholderPac tTeam("PCM M did not return any data for veteran at facility: " + facil ityCode + (_notProd ? "(Non-Pr od)" : "") ); | |
| 72 | } | |
| 73 | }, | |
| 74 | error: f unction (X MLHttpRequ est, textS tatus, err orThrown) { | |
| 75 | writeToCon sole("insi de PCMM er ror callba ck: " + er rorThrown) ; | |
| 76 | fillFtp_pa ctIdWithPl aceholderP actTeam("E rror query ing PCMM: " + errorT hrown); | |
| 77 | }, | |
| 78 | async: t rue, | |
| 79 | cache: f alse | |
| 80 | }); | |
| 81 | } | |
| 82 | } | |
| 83 | el se{ | |
| 84 | writ eToConsole ("PCMM is disabled o r we are m issing ftp _PatientSu mmaryAPIUR L from Act ive Settin gs."); | |
| 85 | ||
| 86 | Xrm. Page.getCo ntrol("Web Resource_V eteranPACT Team").set Visible(fa lse); | |
| 87 | Xrm. Page.getCo ntrol("ftp _pactid"). setVisible (false); | |
| 88 | Xrm. Page.getAt tribute("f tp_pactid" ).setSubmi tMode("alw ays"); | |
| 89 | Xrm. Page.getCo ntrol("ftp _primaryca reprovider ").setVisi ble(false) ; | |
| 90 | Xrm. Page.getAt tribute("f tp_primary careprovid er").setSu bmitMode(" always"); | |
| 91 | ||
| 92 | fill Ftp_pactId WithPlaceh olderPactT eam("PCMM web servic e calls ar e disabled , or we ar e missing the Patien t Summary API from A ctive Sett ings. Cont act your a dministrat or."); | |
| 93 | } | |
| 94 | } | |
| 95 | ||
| 96 | function p rocessPCHB Assignment (pPatientA ssignment) { | |
| 97 | wr iteToConso le("begin processPCH BAssignmen t"); | |
| 98 | if (!! pPatientAs signment) { | |
| 99 | /* S ummary | |
| 100 | pPatie ntAssignme nt will ha ve either 'primaryCa reAssignme nts' or 'p rimaryCare HBPCAssign ments' (ho me bound a ssignments ). | |
| 101 | Cycle through th e one with data and store them in the te amMembersF romPCMM ar ray and th e PCMMGrid Members ar ray. | |
| 102 | */ | |
| 103 | ||
| 104 | var teamName = ""; | |
| 105 | var teamMember sFromPCMM = []; //em pty array intended t o hold obj ects of sc hema { Nam e, TeamRol eName } | |
| 106 | ||
| 107 | if ( pPatientAs signment.h asOwnPrope rty("prima ryCareAssi gnments") && Array.i sArray(pPa tientAssig nment.prim aryCareAss ignments) && pPatien tAssignmen t.primaryC areAssignm ents.lengt h > 0) { | |
| 108 | //prim aryCareAss ignments a rray | |
| 109 | writeT oConsole(" found prim aryCareAss ignments") ; | |
| 110 | var pc Assignment = pPatien tAssignmen t.primaryC areAssignm ents[0]; | |
| 111 | teamNa me = !!pcA ssignment. teamName ? pcAssignm ent.teamNa me : ""; | |
| 112 | if (pc Assignment .hasOwnPro perty("tea mletMember s") && $.i sArray(pcA ssignment. teamletMem bers) && p cAssignmen t.teamletM embers.len gth > 0) { | |
| 113 | for (var i = 0, l = pcAssign ment.teaml etMembers. length; i < l; i++) { | |
| 114 | var thisTe amletMembe r = pcAssi gnment.tea mletMember s[i]; | |
| 115 | if (thisTe amletMembe r.hasOwnPr operty("St affContact ") && !!th isTeamletM ember.Staf fContact) { | |
| 116 | va r sc = thi sTeamletMe mber.Staff Contact; | |
| 117 | if (sc.hasOw nProperty( "Name") && !!sc.Name ) { | |
| 118 | var person = { Name: sc. Name, Team RoleName: sc.TeamRol eName }; | |
| 119 | team MembersFro mPCMM.push (person); | |
| 120 | PCMM GridMember s.push(per son); | |
| 121 | } | |
| 122 | } | |
| 123 | } | |
| 124 | finished GettingPri maryCarePr oviders = true; | |
| 125 | } | |
| 126 | else { | |
| 127 | finished GettingPri maryCarePr oviders = true; | |
| 128 | } | |
| 129 | } | |
| 130 | else if (pPati entAssignm ent.hasOwn Property(" primaryCar eHBPCAssig nments") & & Array.is Array(pPat ientAssign ment.prima ryCareHBPC Assignment s) && pPat ientAssign ment.prima ryCareHBPC Assignment s.length > 0) { | |
| 131 | //prim aryCareHBP CAssignmen ts array | |
| 132 | writeT oConsole(" found prim aryCareHBP CAssignmen ts"); | |
| 133 | var ho meboundPCA ssignment = pPatient Assignment .primaryCa reHBPCAssi gnments[0] ; | |
| 134 | teamNa me = !!hom eboundPCAs signment.t eamName ? homeboundP CAssignmen t.teamName : ""; | |
| 135 | if (ho meboundPCA ssignment. hasOwnProp erty("team Members") && homebou ndPCAssign ment.teamM embers.len gth > 0) { | |
| 136 | for (var i = 0, l = homeboun dPCAssignm ent.teamMe mbers.leng th; i < l; i++) { | |
| 137 | var thisTe amMember = homebound PCAssignme nt.teamMem bers[i]; | |
| 138 | if (thisTe amMember.h asOwnPrope rty("Name" ) && !!thi sTeamMembe r.Name) { | |
| 139 | va r person = { Name: t hisTeamMem ber.Name, TeamRoleNa me: thisTe amMember.T eamRoleNam e }; | |
| 140 | te amMembersF romPCMM.pu sh(person) ; | |
| 141 | PC MMGridMemb ers.push(p erson); | |
| 142 | } | |
| 143 | } | |
| 144 | finished GettingPri maryCarePr oviders = true; | |
| 145 | } | |
| 146 | else { | |
| 147 | finished GettingPri maryCarePr oviders = true; | |
| 148 | } | |
| 149 | } | |
| 150 | else { | |
| 151 | //all care assig nment arra ys are emp ty | |
| 152 | finish edGettingP rimaryCare Providers = true; | |
| 153 | } | |
| 154 | ||
| 155 | if ( !!teamName ) { | |
| 156 | writeT oConsole(" retrieving ftp_pact record: " + teamName ); | |
| 157 | //find or create a PACT te am record called nam ed <teamNa me> | |
| 158 | var re trievedPAC TTeams = [ ]; | |
| 159 | var qu eryString = "$select =ftp_name, ftp_pactId ,ftp_ftp_p act_system user/First Name,ftp_f tp_pact_sy stemuser/L astName,ft p_ftp_pact _systemuse r/SystemUs erId,ftp_f tp_pact_sy stemuser/F ullName,ft p_ftp_pact _systemuse r/DomainNa me"; | |
| 160 | queryS tring += " &$filter=f tp_name eq '" + team Name + "'" | |
| 161 | queryS tring += " &$expand=f tp_ftp_pac t_systemus er"; | |
| 162 | SDK.RE ST.retriev eMultipleR ecords( | |
| 163 | "ftp_pac t", | |
| 164 | queryStr ing, | |
| 165 | function (retrieve dRecords) { | |
| 166 | if (typeof retrieved Records != "undefine d" && !!re trievedRec ords) retr ievedPACTT eams = ret rievedPACT Teams.conc at(retriev edRecords) ; | |
| 167 | }, | |
| 168 | errorHan dler, | |
| 169 | function () { | |
| 170 | if (retrie vedPACTTea ms.length > 0) { | |
| 171 | wr iteToConso le("found " + teamNa me + " PAC T team rec ord in CRM "); | |
| 172 | se tftp_pacti d(retrieve dPACTTeams [0]); | |
| 173 | ma tchPCTeamM embersToPA CTTeam(ret rievedPACT Teams[0], teamMember sFromPCMM, false, nu ll); //aft er calling it here, this metho d calls it self for t he rest of the PACT team membe rs from PC MM | |
| 174 | } | |
| 175 | else { | |
| 176 | wr iteToConso le("did no t find " + teamName + " PACT t eam record in CRM, c reating.") ; | |
| 177 | va r newPact = { | |
| 178 | ftp_ name: team Name | |
| 179 | }; | |
| 180 | SD K.REST.cre ateRecord( | |
| 181 | newP act, | |
| 182 | "ftp _pact", | |
| 183 | func tion (crea tedPACTTea m) { | |
| 184 | setftp _pactid(cr eatedPACTT eam); | |
| 185 | matchP CTeamMembe rsToPACTTe am(created PACTTeam, teamMember sFromPCMM, false, nu ll); //aft er calling it here, this metho d calls it self for t he rest of the PACT team membe rs from PC MM | |
| 186 | }, | |
| 187 | erro rHandler | |
| 188 | ); | |
| 189 | } | |
| 190 | }); | |
| 191 | } | |
| 192 | else { | |
| 193 | //if w e didn't f ind a team Name from the primar yCareAssig nments or primaryCar eHBPCAssig nments nod es, set ft p_pactId o n the vete ran to PAC T Teamlet 12 | |
| 194 | fillFt p_pactIdWi thPlacehol derPactTea m(); | |
| 195 | } | |
| 196 | } | |
| 197 | el se{ | |
| 198 | writ eToConsole ("patient assingnmen t object i s empty.") ; | |
| 199 | fi nishedGett ingPrimary CareProvid ers = true ; | |
| 200 | re turn; | |
| 201 | } | |
| 202 | } | |
| 203 | ||
| 204 | function p rocessMent alHealthPr ovider(pPa tientAssig nment) { | |
| 205 | /* Summary | |
| 206 | pPat ientAssign ment will have a men talHealthA ssignments property that is an array. | |
| 207 | Cycl e through the array and store its member s in the t eamMembers FromPCMM a rray and t he PCMMGri dMembers a rray. | |
| 208 | */ | |
| 209 | wr iteToConso le("begin processMen talHealthP rovider()" ); | |
| 210 | if (!!pPatien tAssignmen t){ | |
| 211 | if ( pPatientAs signment.h asOwnPrope rty("menta lHealthAss ignments") && !!pPat ientAssign ment.menta lHealthAss ignments & & Array.is Array(pPat ientAssign ment.menta lHealthAss ignments) && pPatien tAssignmen t.mentalHe althAssign ments.leng th > 0) { | |
| 212 | var me ntalHealth Assignment = pPatien tAssignmen t.mentalHe althAssign ments[0]; | |
| 213 | if (me ntalHealth Assignment .hasOwnPro perty("tea mName") && !!mentalH ealthAssig nment.team Name) { | |
| 214 | var team Name = men talHealthA ssignment. teamName; | |
| 215 | if (ment alHealthAs signment.h asOwnPrope rty("menta lHealthTre atmentCoor d") && !!m entalHealt hAssignmen t.mentalHe althTreatm entCoord) { | |
| 216 | var MHTC = mentalHea lthAssignm ent.mental HealthTrea tmentCoord ; | |
| 217 | writeToCon sole("got mentalHeal thAssignme nt.mentalH ealthTreat mentCoord object."); | |
| 218 | PCMMGridMe mbers.push (MHTC); | |
| 219 | finishedGe ttingMHTC = true; | |
| 220 | ||
| 221 | //find or create the PACT Team record ma tching tea mName | |
| 222 | if (!!team Name) { | |
| 223 | // find or cr eate a PAC T team rec ord called named <te amName> | |
| 224 | va r retrieve dPACTTeams = []; | |
| 225 | va r queryStr ing = "$fi lter=ftp_n ame eq '" + teamName + "' and statecode/ Value eq 0 &$expand=f tp_ftp_pac t_systemus er&$select =ftp_name, ftp_pactId ,ftp_ftp_p act_system user/First Name,ftp_f tp_pact_sy stemuser/L astName,ft p_pactId,f tp_ftp_pac t_systemus er/FullNam e,ftp_ftp_ pact_syste muser/Syst emUserId"; | |
| 226 | SD K.REST.ret rieveMulti pleRecords ( | |
| 227 | "ftp _pact", | |
| 228 | quer yString, | |
| 229 | func tion (retr ievedRecor ds) { | |
| 230 | if (ty peof retri evedRecord s != "unde fined") re trievedPAC TTeams = r etrievedPA CTTeams.co ncat(retri evedRecord s); | |
| 231 | }, | |
| 232 | erro rHandler, | |
| 233 | func tion () { | |
| 234 | if (re trievedPAC TTeams.len gth > 0) { | |
| 235 | matchMHT CToPACTTea m(retrieve dPACTTeams [0], MHTC) ; | |
| 236 | } | |
| 237 | else { | |
| 238 | var newP act = { | |
| 239 | ftp_name: teamName | |
| 240 | }; | |
| 241 | SDK.REST .createRec ord( | |
| 242 | newPact, | |
| 243 | "ftp_pact" , | |
| 244 | function ( createdPAC TTeam) { | |
| 245 | ma tchMHTCToP ACTTeam(cr eatedPACTT eam, MHTC) ; | |
| 246 | }, | |
| 247 | errorHandl er | |
| 248 | ); | |
| 249 | } | |
| 250 | } | |
| 251 | ); | |
| 252 | } | |
| 253 | } | |
| 254 | else { | |
| 255 | finishedGe ttingMHTC = true; | |
| 256 | } | |
| 257 | } | |
| 258 | else { | |
| 259 | finished GettingMHT C = true; | |
| 260 | } | |
| 261 | } | |
| 262 | else { | |
| 263 | finish edGettingM HTC = true ; | |
| 264 | } | |
| 265 | } | |
| 266 | el se{ | |
| 267 | writ eToConsole ("patient assingment object is empty."); | |
| 268 | fi nishedGett ingMHTC = true; | |
| 269 | re turn; | |
| 270 | } | |
| 271 | } | |
| 272 | ||
| 273 | function s etftp_pact id(pPACTTe am){ | |
| 274 | wr iteToConso le("begin setftp_pac tid()"); | |
| 275 | va r attr = X rm.Page.ge tAttribute ("ftp_pact id"); | |
| 276 | if (!!pPACTTe am && !!at tr){ | |
| 277 | VCCM .USDHelper .CopyToUSD Context([" PACTTeam=" + pPACTTe am.ftp_nam e]); | |
| 278 | attr .setValue( [{ | |
| 279 | id: pP ACTTeam.ft p_pactId, | |
| 280 | name: pPACTTeam. ftp_name, | |
| 281 | entity Type: "ftp _pact" | |
| 282 | }]); | |
| 283 | attr .setSubmit Mode("alwa ys"); | |
| 284 | Xrm. Page.getAt tribute("f tp_pactid" ).addOnCha nge(ftp_pa ctid_onCha nge); | |
| 285 | } | |
| 286 | } | |
| 287 | ||
| 288 | function m atchPCTeam MembersToP ACTTeam(pP ACTTeam, p PACTTeamMe mbersFromP CMM, pAlre adySetPrim aryCarePro viderField , pUsersTo UnlinkFrom PACTTeam){ | |
| 289 | wr iteToConso le(""); | |
| 290 | wr iteToConso le("begin matchPCTea mMembersTo PACTTeam() ... pPACTT eamMembers FromPCMM.l ength = " + pPACTTea mMembersFr omPCMM.len gth); | |
| 291 | ||
| 292 | // usersToUnl ink is an array that will end up holding a list of users to update, se tting thei r ftp_PACT id field n ull | |
| 293 | va r usersToU nlink = pU sersToUnli nkFromPACT Team; | |
| 294 | // populate u sersToUnli nk from pP ACTTeam on ly if we h aven't pas sed in an array of u sers alrea dy (pUsers ToUnlinkFr omPACTTeam ) | |
| 295 | if (usersToUn link == nu ll){ | |
| 296 | user sToUnlink = []; | |
| 297 | if ( pPACTTeam. hasOwnProp erty("ftp_ ftp_pact_s ystemuser" ) && pPACT Team.ftp_f tp_pact_sy stemuser.h asOwnPrope rty("resul ts") && pP ACTTeam.ft p_ftp_pact _systemuse r.results. length > 0 ) { | |
| 298 | writeT oConsole(p PACTTeam.f tp_ftp_pac t_systemus er.results .length + " CRM user s already connected to the " + pPACTTeam .ftp_name + " PACT t eam, befor e we add/r emove anyb ody"); | |
| 299 | for (v ar i = 0, l = pPACTT eam.ftp_ft p_pact_sys temuser.re sults.leng th; i < l; i++) { | |
| 300 | usersToU nlink.push (pPACTTeam .ftp_ftp_p act_system user.resul ts[i]); | |
| 301 | } | |
| 302 | } | |
| 303 | else { | |
| 304 | writeT oConsole(" no CRM use rs are cur rently con nected to the " + pP ACTTeam.ft p_name + " PACT team , before w e add/remo ve anybody "); | |
| 305 | } | |
| 306 | } | |
| 307 | ||
| 308 | if (pPACTTeam MembersFro mPCMM.leng th > 0){ | |
| 309 | var alreadySet PrimaryCar eProviderF ield = pAl readySetPr imaryCareP roviderFie ld != null ? pAlread ySetPrimar yCareProvi derField : false; | |
| 310 | var thisTeamMe mber = pPA CTTeamMemb ersFromPCM M.shift(); //cut the length of pPACTTeam MembersFro mPCMM down one at a time | |
| 311 | var splitName = thisTeam Member.Nam e.split(", "); | |
| 312 | var lastName = splitName [0].trim() ; | |
| 313 | var splitFirst MiddleName s = splitN ame.length > 1 ? spl itName[1]. trim().spl it(" ") : ""; | |
| 314 | var firstName = !!splitF irstMiddle Names ? sp litFirstMi ddleNames[ 0] : ""; | |
| 315 | var middleName = !!split FirstMiddl eNames && splitFirst MiddleName s.length > 1 ? split FirstMiddl eNames[1] : ""; | |
| 316 | var fakeFullNa me = lastN ame + ", " + firstNa me + " " + middleNam e; | |
| 317 | var domain Name = fir stName + " ." + lastN ame + "@no domainacco unt. DNS ";/*see if we can ge t PCMM to return ema il address es*/ | |
| 318 | var userQueryS tring = "$ select=Fir stName,Las tName,Syst emUserId,f tp_PACTId, ftp_PACTTe amRole,IsD isabled,Do mainName,F ullName" | |
| 319 | user QueryStrin g += "&$fi lter=Domai nName eq ' " + domain Name + "'" ; | |
| 320 | writ eToConsole ("thisTeam Member: " + fakeFull Name + " ( " + domain Name + ")" ); | |
| 321 | var retrievedU sers = []; | |
| 322 | SDK. REST.retri eveMultipl eRecords( | |
| 323 | "Syste mUser", | |
| 324 | userQu eryString, | |
| 325 | functi on (retrie vedRecords ) { | |
| 326 | if (type of retriev edRecords != "undefi ned" && !! retrievedR ecords) re trievedUse rs = retri evedUsers. concat(ret rievedReco rds); | |
| 327 | }, | |
| 328 | errorH andler, | |
| 329 | functi on () { | |
| 330 | if (retr ievedUsers .length > 0) { | |
| 331 | var foundU ser = retr ievedUsers [0]; | |
| 332 | if(!foundU ser.IsDisa bled){ | |
| 333 | wr iteToConso le("found systemuser " + found User.Domai nName + " in CRM"); | |
| 334 | if (foundUse r.hasOwnPr operty("ft p_PACTId") && !!foun dUser.ftp_ PACTId && foundUser. ftp_PACTId .Id == pPA CTTeam.ftp _pactId && | |
| 335 | foun dUser.hasO wnProperty ("ftp_PACT TeamRole") && foundU ser.ftp_PA CTTeamRole == thisTe amMember.T eamRoleNam e) { | |
| 336 | writ eToConsole (foundUser .FullName + " is alr eady linke d to the " + pPACTTe am.ftp_nam e + " and has the co rrect PACT Team Role ; skipping update.") ; | |
| 337 | user sToUnlink = removeUs erFromUser sToUnlink( foundUser, usersToUn link); | |
| 338 | if ( !alreadySe tPrimaryCa reProvider Field) alr eadySetPri maryCarePr oviderFiel d = setPri maryCarePr oviderFiel d(foundUse r); | |
| 339 | matc hPCTeamMem bersToPACT Team(pPACT Team, pPAC TTeamMembe rsFromPCMM , alreadyS etPrimaryC areProvide rField, us ersToUnlin k);//run t his method again | |
| 340 | } | |
| 341 | el se { | |
| 342 | foun dUser.ftp_ PACTId = { | |
| 343 | Id: pP ACTTeam.ft p_pactId, | |
| 344 | Logica lName: "ft p_pact", | |
| 345 | Name: pPACTTeam. ftp_name | |
| 346 | }; | |
| 347 | foun dUser.ftp_ PACTTeamRo le = thisT eamMember. TeamRoleNa me; | |
| 348 | SDK. REST.updat eRecord( | |
| 349 | foundU ser.System UserId, | |
| 350 | foundU ser, | |
| 351 | "Syste mUser", | |
| 352 | functi on () { | |
| 353 | writeToC onsole("up dated " + foundUser. DomainName + " with PACT team (" + pPACT Team.ftp_n ame + ") a nd PACT te am role (" + thisTea mMember.Te amRoleName + ")"); | |
| 354 | usersToU nlink = re moveUserFr omUsersToU nlink(foun dUser, use rsToUnlink ); | |
| 355 | if (!alr eadySetPri maryCarePr oviderFiel d) already SetPrimary CareProvid erField = setPrimary CareProvid erField(fo undUser); | |
| 356 | matchPCT eamMembers ToPACTTeam (pPACTTeam , pPACTTea mMembersFr omPCMM, al readySetPr imaryCareP roviderFie ld, usersT oUnlink);/ /run this method aga in | |
| 357 | }, | |
| 358 | errorH andler | |
| 359 | ); | |
| 360 | } | |
| 361 | } | |
| 362 | else{ | |
| 363 | wr iteToConso le("found systemuser " + foundU ser.Domain Name + ", but this u ser is dis abled. Sk ipping use r update." ); | |
| 364 | } | |
| 365 | } | |
| 366 | ||
| 367 | //If we didn't fin d thisTeam Member in CRM as a u ser, then retrieve t he 'PACT U SER' CRM t eam, and c reate the new user, and make t he user a member of the team | |
| 368 | else { | |
| 369 | writeToCon sole("did not find " + domainN ame + ", c reating sy stemuser." ); | |
| 370 | var PACTUs erCRMTeam = null; | |
| 371 | var teamQu ery = "$se lect=Name, TeamId,Bus inessUnitI d&$filter= Name eq 'P ACT User' and TeamTy pe/Value e q 0"; | |
| 372 | var retrie vedCRMTeam s = []; | |
| 373 | SDK.REST.r etrieveMul tipleRecor ds( | |
| 374 | "T eam", | |
| 375 | te amQuery, | |
| 376 | fu nction (re trievedRec ords) { | |
| 377 | if ( typeof ret rievedReco rds != "un defined" & & !!retrie vedRecords ) retrieve dCRMTeams = retrieve dCRMTeams. concat(ret rievedReco rds); | |
| 378 | }, | |
| 379 | er rorHandler , | |
| 380 | fu nction () { | |
| 381 | if ( retrievedC RMTeams.le ngth > 0) { | |
| 382 | PACTUs erCRMTeam = retrieve dCRMTeams[ 0]; | |
| 383 | ||
| 384 | //buil d newUser object | |
| 385 | var ne wUser = { | |
| 386 | FirstNam e: firstNa me, | |
| 387 | LastName : lastName , | |
| 388 | MiddleNa me: middle Name, | |
| 389 | ftp_PACT TeamRole: thisTeamMe mber.TeamR oleName, | |
| 390 | IsIntegr ationUser: false, | |
| 391 | UserLice nseType: 3 , | |
| 392 | AccessMo de: { | |
| 393 | Value: 0 | |
| 394 | }, | |
| 395 | DomainNa me: domain Name, | |
| 396 | Business UnitId: { | |
| 397 | Id: PACTUs erCRMTeam. BusinessUn itId.Id, | |
| 398 | LogicalNam e: PACTUse rCRMTeam.B usinessUni tId.Logica lName, | |
| 399 | Name: PACT UserCRMTea m.Business UnitId.Nam e | |
| 400 | }, | |
| 401 | ftp_PACT Id: { | |
| 402 | Id: pPACTT eam.ftp_pa ctId, | |
| 403 | LogicalNam e: "ftp_pa ct", | |
| 404 | Name: pPAC TTeam.ftp_ name | |
| 405 | } | |
| 406 | }; | |
| 407 | SDK.RE ST.createR ecord( | |
| 408 | newUser, | |
| 409 | "SystemU ser", | |
| 410 | function (createdU ser) { | |
| 411 | writeToCon sole("crea ted system user: " + fakeFullNa me + " (" + domainNa me + "). G UID: " + c reatedUser .SystemUse rId); | |
| 412 | addUsersTo Team(creat edUser.Sys temUserId, PACTUserC RMTeam.Tea mId); | |
| 413 | if (!alrea dySetPrima ryCareProv iderField) alreadySe tPrimaryCa reProvider Field = se tPrimaryCa reProvider Field(crea tedUser); | |
| 414 | matchPCTea mMembersTo PACTTeam(p PACTTeam, pPACTTeamM embersFrom PCMM, alre adySetPrim aryCarePro viderField , usersToU nlink); // run this m ethod agai n | |
| 415 | }, | |
| 416 | errorHan dler | |
| 417 | ); | |
| 418 | } | |
| 419 | } | |
| 420 | ); | |
| 421 | } | |
| 422 | } | |
| 423 | ); | |
| 424 | } | |
| 425 | el se{ | |
| 426 | //if all prima ry care te am members PCMM are now in CRM as system users, lin ked to the PACT team , we can n ow update any remain ing system users that should be be linked to this P ACT team | |
| 427 | unli nkUsersFro mPACTTeam( usersToUnl ink); | |
| 428 | } | |
| 429 | } | |
| 430 | ||
| 431 | function r emoveUserF romUsersTo Unlink(pUs er, pUsers ToUnlink){ | |
| 432 | fo r(var i = 0, l = pUs ersToUnlin k.length; i < l; i++ ){ | |
| 433 | if(p UsersToUnl ink[i].Sys temUserId == pUser.S ystemUserI d){ | |
| 434 | pUsers ToUnlink.s plice(i,1) ; | |
| 435 | break; | |
| 436 | } | |
| 437 | } | |
| 438 | re turn pUser sToUnlink; | |
| 439 | } | |
| 440 | ||
| 441 | function u nlinkUsers FromPACTTe am(pUsers) { | |
| 442 | wr iteToConso le("begin unlinkUser sFromPACTT eam()"); | |
| 443 | if (!! pUsers && Array.isAr ray(pUsers ) && pUser s.length > 0) { | |
| 444 | writ eToConsole ("pUsers.l ength: " + pUsers.le ngth); | |
| 445 | var thisUser = pUsers.sh ift(); | |
| 446 | if ( thisUser.h asOwnPrope rty("Syste mUserId") && !!thisU ser.System UserId) { | |
| 447 | thisUs er.ftp_PAC TId = { | |
| 448 | Id: null , | |
| 449 | LogicalN ame: null, | |
| 450 | Name: nu ll | |
| 451 | }; | |
| 452 | SDK.RE ST.updateR ecord( | |
| 453 | thisUser .SystemUse rId, | |
| 454 | thisUser , | |
| 455 | "SystemU ser", | |
| 456 | function () { | |
| 457 | //do nothi ng else wi th this us er | |
| 458 | writeToCon sole("clea red ftp_PA CTId field on system user:" + t hisUser.Fu llName + " {" + this User.Syste mUserId + "}"); | |
| 459 | ||
| 460 | //re-enter this func tion until pUsers is empty | |
| 461 | unlinkUser sFromPACTT eam(pUsers ); | |
| 462 | }, | |
| 463 | errorHan dler | |
| 464 | ); | |
| 465 | } | |
| 466 | } | |
| 467 | el se{ | |
| 468 | writ eToConsole ("no users to unlink ."); | |
| 469 | } | |
| 470 | } | |
| 471 | ||
| 472 | function s etPrimaryC areProvide rField(pUs er) { | |
| 473 | if (!p User || !p User.ftp_P ACTTeamRol e || !pUse r.FullName ) return f alse; | |
| 474 | if (!( pUser.ftp_ PACTTeamRo le == "Pri mary Care Provider" || pUser.f tp_PACTTea mRole == " Associate Provider") ) return f alse; | |
| 475 | ||
| 476 | Xr m.Page.get Attribute( "ftp_prima rycareprov ider").set Value(pUse r.FullName ); | |
| 477 | Xrm.Pa ge.getAttr ibute("ftp _primaryca reprovider ").setSubm itMode("al ways"); | |
| 478 | wr iteToConso le("set Ve teran's ft p_primaryc areprovide r with sys temuser.Fu llName: " + pUser.Fu llName); | |
| 479 | VC CM.USDHelp er.CopyToU SDContext( ["PCP=" + pUser.Full Name]); | |
| 480 | Xr m.Page.get Attribute( "ftp_prima rycareprov ider").fir eOnChange( ); | |
| 481 | return true; | |
| 482 | } | |
| 483 | ||
| 484 | function m atchMHTCTo PACTTeam(p PACTTeam, pMHTC) { | |
| 485 | wr iteToConso le("begin matchMHTCT oPACTTeam( )"); | |
| 486 | if (!p PACTTeam) return; | |
| 487 | //don' t set the ftp_pactid lookup fi eld on the vet form | |
| 488 | ||
| 489 | //save to an arr ay the cur rent list of users w ho current ly referen ce pPACTTe am, so tha t we can r emove that reference if they N O LONGER a re a membe r of pPACT Team accor ding to PC MM | |
| 490 | // for a ment al health PACT team. ..it shoul d just be one user | |
| 491 | // for a newl y-created ftp_pact r ecord, thi s list of users will be empty | |
| 492 | var us ersToUpdat e = []; | |
| 493 | if (pP ACTTeam.ha sOwnProper ty("ftp_ft p_pact_sys temuser") && pPACTTe am.ftp_ftp _pact_syst emuser.has OwnPropert y("results ") && pPAC TTeam.ftp_ ftp_pact_s ystemuser. results.le ngth > 0) { | |
| 494 | writ eToConsole (pPACTTeam .ftp_ftp_p act_system user.resul ts.length + " CRM us ers curren tly connec ted to the " + pPACT Team.ftp_n ame + " PA CT team"); | |
| 495 | fo r (var i = 0, l = pP ACTTeam.ft p_ftp_pact _systemuse r.results. length; i < l; i++) { | |
| 496 | usersToU pdate.push (pPACTTeam .ftp_ftp_p act_system user.resul ts[i]); | |
| 497 | } | |
| 498 | } | |
| 499 | ||
| 500 | if (!! pMHTC) { | |
| 501 | va r teamQuer y = "$sele ct=Name,Te amId,Busin essUnitId& $filter=Na me eq 'PAC T User' an d TeamType /Value eq 0"; | |
| 502 | va r retrieve dCRMTeams = []; | |
| 503 | SD K.REST.ret rieveMulti pleRecords ( | |
| 504 | "Team" , | |
| 505 | teamQu ery, | |
| 506 | functi on (retrie vedRecords ) { | |
| 507 | if (type of retriev edRecords != "undefi ned" && !! retrievedR ecords) re trievedCRM Teams = re trievedCRM Teams.conc at(retriev edRecords) ; | |
| 508 | }, | |
| 509 | errorH andler, | |
| 510 | functi on () { | |
| 511 | if (retr ievedCRMTe ams.length > 0) { | |
| 512 | var PACTUs erCRMTeam = retrieve dCRMTeams[ 0]; | |
| 513 | ||
| 514 | //find or create a s ystemuser for the Me ntal Healt h Treatmen t Coordina tor (pMHTC ) | |
| 515 | //set thei r ftp_PACT Id lookup field to p PACTTeam | |
| 516 | //add the user to th e 'PACT Us er' CRM te am, so it will inher it the tea m's securi ty roles | |
| 517 | //if their ftp_PACTI d and ftp_ PACTTeamRo le are fin e, remove that perso n from use rsToUpdate array | |
| 518 | ||
| 519 | //pMHTC sc hema: { Na me, TeamRo leName, Te amRoleCode , Phone, P ager, Ien } | |
| 520 | writeToCon sole("sear ching for " + pMHTC. Name + " t o connect their CRM user recor d to the " + pPACTTe am.ftp_nam e + " PACT team in C RM"); | |
| 521 | var splitN ame = pMHT C.Name.spl it(","); | |
| 522 | var lastNa me = split Name[0]; | |
| 523 | var splitF irstMiddle Names = sp litName.le ngth > 1 ? splitName [1].trim() .split(" " ) : ""; | |
| 524 | var firstN ame = !!sp litFirstMi ddleNames ? splitFir stMiddleNa mes[0] : " "; | |
| 525 | var middle Name = !!s plitFirstM iddleNames && splitF irstMiddle Names.leng th > 1 ? s plitFirstM iddleNames [1] : ""; | |
| 526 | var fakeFu llName = l astName + ", " + fir stName + " " + middl eName; | |
| 527 | var domain Name = fir stName + " ." + lastN ame + "@no domainacco unt. DNS "; | |
| 528 | var userQu ery = "$se lect=First Name,LastN ame,System UserId,ftp _PACTId,ft p_PACTTeam Role,IsDis abled,Doma inName,Ful lName&$fil ter=Domain Name eq '" + domainN ame + "'"; | |
| 529 | var retrie vedUsers = []; | |
| 530 | SDK.REST.r etrieveMul tipleRecor ds( | |
| 531 | "S ystemUser" , | |
| 532 | us erQuery, | |
| 533 | fu nction (re trievedRec ords) { | |
| 534 | if ( typeof ret rievedReco rds != "un defined" & & !!retrie vedRecords ) retrieve dUsers = r etrievedUs ers.concat (retrieved Records); | |
| 535 | }, | |
| 536 | er rorHandler , | |
| 537 | fu nction () { | |
| 538 | if ( retrievedU sers.lengt h > 0) { | |
| 539 | writeT oConsole(" found syst emuser: " + domainNa me + ", up dating sys temuser.") ; | |
| 540 | var fo undUser = retrievedU sers[0]; | |
| 541 | if(!fo undUser.Is Disabled){ | |
| 542 | if (foun dUser.hasO wnProperty ("ftp_PACT Id") && !! foundUser. ftp_PACTId && foundU ser.ftp_PA CTId.Id == pPACTTeam .ftp_pactI d && | |
| 543 | foundUser. hasOwnProp erty("ftp_ PACTTeamRo le") && fo undUser.ft p_PACTTeam Role == pM HTC.TeamRo leName) { | |
| 544 | writeToCon sole(found User.FullN ame + " is already l inked to t he " + pPA CTTeam.ftp _name + " and has th e correct PACT Team Role; skip ping updat e."); | |
| 545 | //remove t his person from the usersToUpd ate array, because t heir ftp_P ACTId and ftp_PACTTe amRole are already f ine | |
| 546 | usersToUpd ate.splice (i, 1); | |
| 547 | setMentalH ealthTeamF ield(found User); | |
| 548 | } | |
| 549 | else { | |
| 550 | foundUser. ftp_PACTId = { | |
| 551 | Id : pPACTTea m.ftp_pact Id, | |
| 552 | Lo gicalName: "ftp_pact ", | |
| 553 | Na me: pPACTT eam.ftp_na me | |
| 554 | }; | |
| 555 | foundUser. ftp_PACTTe amRole = p MHTC.TeamR oleName; | |
| 556 | SDK.REST.u pdateRecor d( | |
| 557 | fo undUser.Sy stemUserId , | |
| 558 | fo undUser, | |
| 559 | "S ystemUser" , | |
| 560 | fu nction () { | |
| 561 | writ eToConsole ("updated " + foundU ser.Domain Name + " w ith PACT t eam (" + p PACTTeam.f tp_name + ") and PAC T team rol e (" + pMH TC.TeamRol eName + ") "); | |
| 562 | setM entalHealt hTeamField (foundUser ); | |
| 563 | }, | |
| 564 | er rorHandler | |
| 565 | ); | |
| 566 | } | |
| 567 | } | |
| 568 | else{ | |
| 569 | writeToC onsole("fo und system user" + fo undUser.Do mainName + ", but th is user is disabled. Skipping user upda te."); | |
| 570 | } | |
| 571 | } | |
| 572 | else { | |
| 573 | writeT oConsole(" did not fi nd systemu ser: " + d omainName + ", creat ing system user."); | |
| 574 | //buil d user obj ect | |
| 575 | var ne wUser = { | |
| 576 | FirstNam e: firstNa me, | |
| 577 | LastName : lastName , | |
| 578 | MiddleNa me: middle Name, | |
| 579 | ftp_PACT TeamRole: pMHTC.Team RoleName, | |
| 580 | IsIntegr ationUser: false, | |
| 581 | UserLice nseType: 3 , | |
| 582 | AccessMo de: { | |
| 583 | Value: 0 | |
| 584 | }, | |
| 585 | DomainNa me: domain Name, | |
| 586 | Business UnitId: { | |
| 587 | Id: PACTUs erCRMTeam. BusinessUn itId.Id, | |
| 588 | LogicalNam e: PACTUse rCRMTeam.B usinessUni tId.Logica lName, | |
| 589 | Name: PACT UserCRMTea m.Business UnitId.Nam e | |
| 590 | }, | |
| 591 | ftp_PACT Id: { | |
| 592 | Id: pPACTT eam.ftp_pa ctId, | |
| 593 | LogicalNam e: "ftp_pa ct", | |
| 594 | Name: pPAC TTeam.ftp_ name | |
| 595 | } | |
| 596 | }; | |
| 597 | //crea te it | |
| 598 | SDK.RE ST.createR ecord( | |
| 599 | newUser, | |
| 600 | "SystemU ser", | |
| 601 | function (createdU ser) { | |
| 602 | writeToCon sole("crea ted system user: " + fakeFullNa me + " (" + domainNa me + "). G UID: " + c reatedUser .SystemUse rId); | |
| 603 | setMentalH ealthTeamF ield(creat edUser); | |
| 604 | addUsersTo Team(creat edUser.Sys temUserId, PACTUserC RMTeam.Tea mId); | |
| 605 | }, | |
| 606 | errorHan dler | |
| 607 | ); | |
| 608 | } | |
| 609 | } | |
| 610 | ); | |
| 611 | } | |
| 612 | } | |
| 613 | ); | |
| 614 | } | |
| 615 | el se { | |
| 616 | // even if we don't lin k a new MH TC user to pPACTTeam for the f irst time, still nee d to unlin k "old" me mbers of p PACTTeam | |
| 617 | un linkUsersF romPACTTea m(usersToU pdate); | |
| 618 | } | |
| 619 | } | |
| 620 | ||
| 621 | function s etMentalHe althTeamFi eld(pUser) { | |
| 622 | wr iteToConso le("begin setMentalH ealthTeamF ield()"); | |
| 623 | if (!! pUser && ! !pUser.ftp _PACTTeamR ole && !!p User.FullN ame) { | |
| 624 | if (pUser.ft p_PACTTeam Role == "( mhtc) Addi ction Ther apist") { | |
| 625 | var MH TCAttr = X rm.Page.ge tAttribute ("ftp_ment alhealthte am"); | |
| 626 | if(!!M HTCAttr){ | |
| 627 | MHTCAttr .setValue( pUser.Full Name); | |
| 628 | MHTCAttr .setSubmit Mode("alwa ys"); | |
| 629 | writeToC onsole("se t ftp_ment alhealthte am to " + pUser.Full Name); | |
| 630 | } | |
| 631 | else{ | |
| 632 | writeToC onsole("di d not set ftp_mental healthteam to becaus e attribut e is not o n form."); | |
| 633 | } | |
| 634 | } | |
| 635 | } | |
| 636 | } | |
| 637 | ||
| 638 | function a ddUsersToT eam(pUserI ds, pTeamI d) { | |
| 639 | wr iteToConso le("begin addUsersTo Team. pTe amId: " + pTeamId); | |
| 640 | var se rviceURL = Xrm.Page. context.ge tClientUrl () + "/XRM Services/2 011/Organi zation.svc /web"; | |
| 641 | var re questMain = ""; | |
| 642 | reques tMain += " <s:Envelop e xmlns:s= \"http://s chemas.xml soap.org/s oap/envelo pe/\">"; | |
| 643 | reques tMain += " <s:Body> "; | |
| 644 | reques tMain += " <Execu te xmlns=\ "http://sc hemas.micr osoft.com/ xrm/2011/C ontracts/S ervices\" xmlns:i=\" http://www .w3.org/20 01/XMLSche ma-instanc e\">"; | |
| 645 | reques tMain += " <req uest i:typ e=\"b:AddM embersTeam Request\" xmlns:a=\" http://sch emas.micro soft.com/x rm/2011/Co ntracts\" xmlns:b=\" http://sch emas.micro soft.com/c rm/2011/Co ntracts\"> "; | |
| 646 | reques tMain += " <a :Parameter s xmlns:c= \"http://s chemas.dat acontract. org/2004/0 7/System.C ollections .Generic\" >"; | |
| 647 | reques tMain += " <a:KeyValu ePairOfstr inganyType >"; | |
| 648 | reques tMain += " <c:key>T eamId</c:k ey>"; | |
| 649 | reques tMain += " <c:value i:type=\" d:guid\" x mlns:d=\"h ttp://sche mas.micros oft.com/20 03/10/Seri alization/ \">" + pTe amId + "</ c:value>"; | |
| 650 | reques tMain += " </a:KeyVal uePairOfst ringanyTyp e>"; | |
| 651 | reques tMain += " <a:KeyValu ePairOfstr inganyType >"; | |
| 652 | reques tMain += " <c:key>M emberIds</ c:key>"; | |
| 653 | reques tMain += " <c:value i:type=\" d:ArrayOfg uid\" xmln s:d=\"http ://schemas .microsoft .com/2003/ 10/Seriali zation/Arr ays\">"; | |
| 654 | if (Ar ray.isArra y(pUserIds )) { | |
| 655 | fo r (var i = 0, l = pU serIds.len gth; i < l ; i++) { | |
| 656 | writeT oConsole(" adding sys temuser {" + pUserId s[i] + "} to team {" + pTeamId + "}"); | |
| 657 | requestM ain += " <d:guid> " + pUserI ds[i] + "< /d:guid>"; | |
| 658 | } | |
| 659 | } else { | |
| 660 | writ eToConsole ("adding s ystemuser {" + pUser Ids + "} t o team {" + pTeamId + "}"); | |
| 661 | re questMain += " <d :guid>" + pUserIds + "</d:guid >"; | |
| 662 | } | |
| 663 | reques tMain += " </c:valu e>"; | |
| 664 | reques tMain += " </a:KeyVal uePairOfst ringanyTyp e>"; | |
| 665 | reques tMain += " </ a:Paramete rs>"; | |
| 666 | reques tMain += " <a :RequestId i:nil=\"t rue\" />"; | |
| 667 | reques tMain += " <a :RequestNa me>AddMemb ersTeam</a :RequestNa me>"; | |
| 668 | reques tMain += " </re quest>"; | |
| 669 | reques tMain += " </Exec ute>"; | |
| 670 | reques tMain += " </s:Body >"; | |
| 671 | reques tMain += " </s:Envelo pe>"; | |
| 672 | var re q = new XM LHttpReque st(); | |
| 673 | req.op en("POST", serviceUR L, true); | |
| 674 | // Res ponses wil l return X ML. It isn 't possibl e to retur n JSON. | |
| 675 | req.se tRequestHe ader("Acce pt", "appl ication/xm l, text/xm l, */*"); | |
| 676 | req.se tRequestHe ader("Cont ent-Type", "text/xml ; charset= utf-8"); | |
| 677 | req.se tRequestHe ader("SOAP Action", " http://sch emas.micro soft.com/x rm/2011/Co ntracts/Se rvices/IOr ganization Service/Ex ecute"); | |
| 678 | var su ccessCallb ack = null ; | |
| 679 | var er rorCallbac k = null; | |
| 680 | req.on readystate change = f unction () { }; | |
| 681 | req.se nd(request Main); | |
| 682 | wr iteToConso le("sent r equest to add user t o team."); | |
| 683 | } | |
| 684 | ||
| 685 | function f tp_primary careprovid er_onChang e(){ | |
| 686 | VC CM.USDHelp er.CopyToU SDContext( ["PCP=" + Xrm.Page.g etAttribut e("ftp_pri marycarepr ovider").g etValue()] ); | |
| 687 | } | |
| 688 | ||
| 689 | function f tp_pactid_ onChange() { | |
| 690 | wr iteToConso le("begin ftp_pactid _onChange( )"); | |
| 691 | //cycl e through users unde r selected PACT who have a rol e, and upd ate some f ields on t he form wi th their n ames | |
| 692 | var pa ctTeamValu e = Xrm.Pa ge.getAttr ibute("ftp _pactid"). getValue() ; | |
| 693 | if (!p actTeamVal ue) return ; | |
| 694 | VC CM.USDHelp er.CopyToU SDContext( ["PACTTeam =" + pactT eamValue[0 ].name]); | |
| 695 | wr iteToConso le("PACT t eam: " + p actTeamVal ue[0].name ); | |
| 696 | var qu eryString = "$select =FullName, ftp_PACTId &$filter=f tp_PACTId/ Id eq guid '" + pactT eamValue[0 ].id + "' and ftp_PA CTTeamRole ne null"; | |
| 697 | var re trievedUse rs = []; | |
| 698 | SDK.RE ST.retriev eMultipleR ecords( | |
| 699 | "S ystemUser" , | |
| 700 | qu eryString, | |
| 701 | fu nction (re trievedRec ords) { | |
| 702 | if (type of retriev edRecords != "undefi ned" && !! retrievedR ecords) re trievedUse rs = retri evedUsers. concat(ret rievedReco rds); | |
| 703 | }, | |
| 704 | er rorHandler , | |
| 705 | fu nction () { | |
| 706 | if (retr ievedUsers .length > 0) { | |
| 707 | writeToC onsole("fo und " + re trievedUse rs.length + " users on this PA CT team.") ; | |
| 708 | var alreadySet PrimaryCar eProviderF ield = fal se; | |
| 709 | var alreadySet MentalHeal thTeamFiel d = false; | |
| 710 | writeToC onsole("cy cling thro ugh users to find Pr imary Care Provider (or Associ ate Provid er), and ( mhtc) Addi ction Ther apist."); | |
| 711 | for (var i = 0 , l = retr ievedUsers .length; i < l && (! alreadySet PrimaryCar eProviderF ield || !a lreadySetM entalHealt hTeamField ) ; i++) { | |
| 712 | var thisUs er = retri evedUsers[ i]; | |
| 713 | if (!alrea dySetPrima ryCareProv iderField && (thisUs er.ftp_PAC TTeamRole == "Primar y Care Pro vider" || thisUser.f tp_PACTTea mRole == " Associate Provider") ) { | |
| 714 | alread ySetPrimar yCareProvi derField = setPrimar yCareProvi derField(t hisUser); | |
| 715 | } | |
| 716 | if (!alrea dySetMenta lHealthTea mField && thisUser.f tp_PACTTea mRole == " (mhtc) Add iction The rapist") { | |
| 717 | alread ySetMental HealthTeam Field = se tMentalHea lthTeamFie ld(thisUse r); | |
| 718 | } | |
| 719 | } | |
| 720 | } | |
| 721 | } | |
| 722 | ); | |
| 723 | } | |
| 724 | ||
| 725 | function f illFtp_pac tIdWithPla ceholderPa ctTeam(pPC MMErrorTex t) { | |
| 726 | wr iteToConso le("begin fillFtp_pa ctIdWithPl aceholderP actTeam()" ); | |
| 727 | var re trievedPAC TTeams = [ ]; | |
| 728 | va r placehol derPACTTea mName = "P ACT team n ot assigne d"; | |
| 729 | var qu eryString = "$select =ftp_name, ftp_pactId &$filter=f tp_name eq '" + plac eholderPAC TTeamName + "'"; | |
| 730 | SDK.RE ST.retriev eMultipleR ecords( | |
| 731 | "f tp_pact", | |
| 732 | qu eryString, | |
| 733 | fu nction (re trievedRec ords) { | |
| 734 | if (type of retriev edRecords != "undefi ned" && !! retrievedR ecords) re trievedPAC TTeams = r etrievedPA CTTeams.co ncat(retri evedRecord s); | |
| 735 | }, | |
| 736 | er rorHandler , | |
| 737 | fu nction () { | |
| 738 | if (retr ievedPACTT eams.lengt h > 0) { | |
| 739 | var placeholde rPACTRecor d = retrie vedPACTTea ms[0]; | |
| 740 | writeToC onsole("go t placehol der ftp_pa ct record :" + place holderPACT TeamName); | |
| 741 | Xrm. Page.getAt tribute("f tp_pactid" ).setValue ([{ | |
| 742 | id: placeh olderPACTR ecord.ftp_ pactId, | |
| 743 | name: plac eholderPAC TRecord.ft p_name, | |
| 744 | entityType : "ftp_pac t" | |
| 745 | } | |
| 746 | ]); | |
| 747 | Xrm.Page .getAttrib ute("ftp_p actid").se tSubmitMod e("always" ); | |
| 748 | writeToC onsole("se t Veteran' s ftp_pact id field") ; | |
| 749 | if ( pcmm_Enabl ed == true ) { | |
| 750 | var alertT ext = !!pP CMMErrorTe xt ? pPCMM ErrorText : "Notify your PCMM Administra tor to set up this v eteran's C are Team A ssignment in PCMM. Y ou cannot assign Req uests unti l this is complete." ; | |
| 751 | Xrm.Page.u i.setFormN otificatio n(alertTex t, "INFO", "noPACTFr omPCMM"); | |
| 752 | } | |
| 753 | ||
| 754 | fini shedGettin gPrimaryCa reProvider s = true; | |
| 755 | fini shedGettin gMHTC = tr ue; | |
| 756 | } | |
| 757 | } | |
| 758 | ); | |
| 759 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.