114. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/4/2017 8:32:41 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.

114.1 Files compared

# Location File Last Modified
1 VCCM.zip\VCCM\CRM_solutions\VCCMResources\WebResources ftp_RequestJScriptrequest_GetSurrogatejs38E9D3A0-104D-E711-944F-0050568D743D Tue Nov 7 11:34:40 2017 UTC
2 VCCM.zip\VCCM\CRM_solutions\VCCMResources\WebResources ftp_RequestJScriptrequest_GetSurrogatejs38E9D3A0-104D-E711-944F-0050568D743D Mon Dec 4 13:05:18 2017 UTC

114.2 Comparison summary

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

114.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

114.4 Active regular expressions

No regular expressions were active.

114.5 Comparison detail

  1   //request_ GetSurroga te.js
  2   //Contains  functions  used on t he request  form to r etrieve VI A surrogat e data
  3   //Requires  jQuery lo aded on th e CRM Form
  4  
  5   //Static V ariables
  6   var rgs_cr mOdataEndP oint = '/X RMServices /2011/Orga nizationDa ta.svc';
  7   var rgs_se rverUrl =  Xrm.Page.c ontext.get ClientUrl( );
  8  
  9   //var rgs_ GetSurroga teUrl = 'h ttps:// se r
v e r
/WebParts/ DEV/api/VI A/surrogat e/1.0/json ';    //OLD MANU AL DEV URL
  10   var rgs_Ge tSurrogate Url = '';
  11   var rgs_ba seServiceE ndpointUrl  = null;
  12   var rgs_re questingAp p = null;
  13   var rgs_co nsumingApp Token = nu ll;
  14   var rgs_co nsumingApp Password =  null;
  15  
  16   //Required  function,  used by L ogin Contr ol
  17   function v cmn_initVi aDropdownC ontrols()  {
  18       //Func tion is tr iggered by  The VistA  Login Con trol
  19       try {
  20           // Not used f or this en tity form,  but must  exist here .
  21       }
  22       catch  (err) {
  23           al ert('Reque st Surroga te VIA Log in Functio n Error(vc mn_initVia DropdownCo ntrols): '  + err.mes sage);
  24       }
  25   }
  26  
  27   function r gs_assignT oSelf() {
  28       try {
  29           // Prompt use r to confi rm assigni ng record  to self
  30           Xr m.Utility. confirmDia log("Would  you like  to assign  this reque st to your self?, Sel ect OK if  Yes, other wise CANCE L.",
  31                function  () {
  32                    //Ch eck the st atus of th e record,  do not pro ceed if re ad only
  33                    if ( Xrm.Page.u i.getFormT ype() >= 3 ) {
  34                         alert("The  current r equest can not be ass igned due  to the cur rent read- only statu s!");
  35                         return fal se;
  36                    }
  37                    //Ge t the curr ent user g uid & Name
  38                    var  rgs_curren tUserId =  Xrm.Page.c ontext.get UserId();
  39                    var  rgs_curren tUserName  = Xrm.Page .context.g etUserName ();
  40  
  41                    //Ch eck if VIA  Login coo kie exist  (not expir ed)
  42                    var  rgs_ViaLog inCookie =  rgs_getCo okie("vias essionlink ");
  43  
  44                    if ( rgs_ViaLog inCookie = = "") {
  45                         alert("You r VISTA se ssion has  expired. I n order to  assign th is request , you must  be logged  into VIST A!");
  46                         Xrm.Page.u i.tabs.get ('Tab_Vist ALogin').s etVisible( true);
  47                         Xrm.Page.u i.tabs.get ('Tab_Vist ALogin').s etFocus();
  48                         return fal se;
  49                    }
  50  
  51                    //Up date the A ssignee Ty pe attribu te to User
  52                    Xrm. Page.getAt tribute("f tp_assigne etype").se tValue(100 000000); / /User
  53                    Xrm. Page.getAt tribute("f tp_assigne etype").se tSubmitMod e('always' );
  54                    //Tr igger Asig nee Type O n Change e vent
  55                    Xrm. Page.getAt tribute("f tp_assigne etype").fi reOnChange ();
  56                    //Wa it 1 secon d before p roceeding
  57                    setT imeout(fun ction () {
  58                         //Set the  selected u ser to the  current u ser
  59                         Xrm.Page.g etAttribut e("ftp_use rselected" ).setValue ([{
  60                             id: rg s_currentU serId,
  61                             name:  rgs_curren tUserName,
  62                             entity Type: "sys temuser"
  63                         }]);
  64                         Xrm.Page.g etAttribut e("ftp_use rselected" ).setSubmi tMode('alw ays');
  65                         //Trigger  Selected U ser On Cha nge event
  66                         Xrm.Page.g etAttribut e("ftp_use rselected" ).fireOnCh ange();
  67                    }, 1 000);
  68                }
  69           );
  70       }
  71       catch  (err) {
  72           al ert('Reque st Assign  Button Fun ction Erro r(rgs_assi gnToSelf):  ' + err.m essage);
  73       }
  74   }
  75  
  76   function r gs_getSurr ogate() {
  77       try {
  78           Xr m.Page.ui. clearFormN otificatio n("SURR100 1");
  79           // If selecte d user is  null, then  exit
  80           va r rgs_user SelectedVa lue = Xrm. Page.getAt tribute("f tp_usersel ected").ge tValue();
  81           if  (rgs_user SelectedVa lue == nul l) {
  82                return f alse;
  83           }
  84  
  85           // Turn on Su rrogate Pr ocessing M essage.... .
  86           Xr m.Page.ui. setFormNot ification( "Checking  for VIA Su rrogates f or the ass igned user , please w ait..", "I NFO", "SUR R1001");
  87  
  88           // GET CRM SE TTINGS WEB  SERVICE U RLS
  89           va r rgs_cond itionalFil ter = "(mc s_name eq  'Active Se ttings')";
  90           rg s_getMulti pleEntityD ataAsync(' mcs_settin gSet', 'ft p_DACURL,  ftp_VIASur rogateURL,  ftp_IsPro ductionEnv ironment,  ftp_VIASer viceBaseUR L, ftp_VIA Requesting Applicatio nCode, ftp _VIAConsum ingApplica tionToken,  ftp_VIACo nsumingApp licationPa ssword', r gs_conditi onalFilter , 'mcs_nam e', 'asc',  0, rgs_vi aSurrogate Setting_re sponse);
  91       }
  92       catch  (err) {
  93           al ert('Reque st Surroga te Functio n Error(rg s_getSurro gate): ' +  err.messa ge);
  94           Xr m.Page.ui. clearFormN otificatio n("SURR100 1");
  95       }
  96   }
  97  
  98   function r gs_viaSurr ogateSetti ng_respons e(rgs_sett ingData, r gs_lastSki p) {
  99       try {
  100           // rgs_lastSk ip is the  starting p oint in th e result ( use if mor e than 50  records) / /Not used  in this sc enario
  101           va r rgs_DacU rl = null;
  102           va r rgs_ViaS urrogateAp iUrl = nul l;
  103           fo r (var i =  0; i <= r gs_setting Data.d.res ults.lengt h - 1; i++ ) {
  104                //Get in fo
  105                if (rgs_ settingDat a.d.result s[i].ftp_D ACURL != n ull) { rgs _DacUrl =  rgs_settin gData.d.re sults[i].f tp_DACURL;  }
  106                if (rgs_ settingDat a.d.result s[i].ftp_V IASurrogat eURL != nu ll) { rgs_ ViaSurroga teApiUrl =  rgs_setti ngData.d.r esults[i]. ftp_VIASur rogateURL;  }
  107                if (rgs_ settingDat a.d.result s[i].ftp_V IAServiceB aseURL !=  null) { rg s_baseServ iceEndpoin tUrl = rgs _settingDa ta.d.resul ts[i].ftp_ VIAService BaseURL; }
  108                if (rgs_ settingDat a.d.result s[i].ftp_V IARequesti ngApplicat ionCode !=  null) { r gs_request ingApp = r gs_setting Data.d.res ults[i].ft p_VIAReque stingAppli cationCode ; }
  109                if (rgs_ settingDat a.d.result s[i].ftp_V IAConsumin gApplicati onToken !=  null) { r gs_consumi ngAppToken  = rgs_set tingData.d .results[i ].ftp_VIAC onsumingAp plicationT oken; }
  110                if (rgs_ settingDat a.d.result s[i].ftp_V IAConsumin gApplicati onPassword  != null)  { rgs_cons umingAppPa ssword = r gs_setting Data.d.res ults[i].ft p_VIAConsu mingApplic ationPassw ord; }
  111                break;
  112           }
  113           if  (rgs_DacU rl != null  && rgs_Vi aSurrogate ApiUrl !=  null) {
  114                //Constr uct full w eb service  URL
  115                rgs_GetS urrogateUr l = rgs_Da cUrl + rgs _ViaSurrog ateApiUrl;
  116           }
  117           el se {
  118                Xrm.Page .ui.setFor mNotificat ion("ERROR : THE VIA  GET SURROG ATE SERVIC E URL IS M ISSING, PL EASE CONTA CT TECHNIC AL SUPPORT !", "ERROR ", "VISTAS ERVICE");
  119                //Exit p rocess, cl ear notifi cation mes sage
  120                Xrm.Page .ui.clearF ormNotific ation("SUR R1001");
  121                Xrm.Page .getAttrib ute("ftp_u serselecte d").setVal ue(null);
  122                Xrm.Page .getAttrib ute("ftp_u serselecte d").setSub mitMode('a lways');
  123                return f alse;
  124           }
  125           if  (rgs_base ServiceEnd pointUrl = = null ||  rgs_reques tingApp ==  null || r gs_consumi ngAppToken  == null | | rgs_cons umingAppPa ssword ==  null) {
  126                Xrm.Page .ui.setFor mNotificat ion("ERROR : THE 'VIA  CONFIGURA TION IS MI SSING DATA  IN THE 'S ettings En tity', PLE ASE CONTAC T TECHNICA L SUPPORT! ", "ERROR" , "VISTASE RVICE");
  127                //Exit p rocess, cl ear notifi cation mes sage
  128                Xrm.Page .ui.clearF ormNotific ation("SUR R1001");
  129                Xrm.Page .getAttrib ute("ftp_u serselecte d").setVal ue(null);
  130                Xrm.Page .getAttrib ute("ftp_u serselecte d").setSub mitMode('a lways');
  131                return f alse;
  132           }
  133           // Decrypt VI A Service  Connector  Items
  134           rg s_requesti ngApp = rg s_decryptS erviceConn ector(rgs_ requesting App, 4);
  135           rg s_consumin gAppToken  = rgs_decr yptService Connector( rgs_consum ingAppToke n, 6);
  136           rg s_consumin gAppPasswo rd = rgs_d ecryptServ iceConnect or(rgs_con sumingAppP assword, 8 );
  137  
  138           // Get the se lected use r value
  139           va r rgs_user SelectedVa lue = Xrm. Page.getAt tribute("f tp_usersel ected").ge tValue();
  140           // Check if a  record al ready exis ts for the  selected  CRM user
  141           va r rgs_cros sReference Id = null;
  142           va r rgs_cros sReference Duz = null ;
  143           va r rgs_cros sReference Name = nul l;
  144           va r rgs_cond itionalFil ter = "ftp _crmuser/I d eq (guid '" + rgs_u serSelecte dValue[0]. id + "')";
  145           va r rgs_cros sReference Data = rgs _getMultip leEntityDa taSync('ft p_useridSe t', 'ftp_u seridId, f tp_vistadu z, ftp_vis tausername ', rgs_con ditionalFi lter, 'ftp _name', 'a sc', 0);
  146           if  (rgs_cros sReference Data != nu ll) {
  147                for (var  i = 0; i  <= rgs_cro ssReferenc eData.d.re sults.leng th - 1; i+ +) {
  148                    //Ge t Info
  149                    if ( rgs_crossR eferenceDa ta.d.resul ts[i].ftp_ useridId ! = null) {  rgs_crossR eferenceId  = rgs_cro ssReferenc eData.d.re sults[i].f tp_useridI d; }
  150                    if ( rgs_crossR eferenceDa ta.d.resul ts[i].ftp_ vistaduz ! = null) {  rgs_crossR eferenceDu z = rgs_cr ossReferen ceData.d.r esults[i]. ftp_vistad uz; }
  151                    if ( rgs_crossR eferenceDa ta.d.resul ts[i].ftp_ vistausern ame != nul l) { rgs_c rossRefere nceName =  rgs_crossR eferenceDa ta.d.resul ts[i].ftp_ vistausern ame; }
  152                    brea k;
  153                }
  154           }
  155  
  156           if  (rgs_cros sReference Id == null ) {
  157                //Values  are null,  inform us er and per form stand ard assign ement and  exit
  158                Xrm.Page .ui.setFor mNotificat ion("The s elected us er does no t have a V IA/CRM Cro ss Referen ce record.  A surroga te check w as not per formed!",  "INFO", "S URR1001");
  159                Xrm.Page .getAttrib ute("owner id").setVa lue([{
  160                    id:  rgs_userSe lectedValu e[0].id,
  161                    name : rgs_user SelectedVa lue[0].nam e,
  162                    enti tyType: "s ystemuser"
  163                }]);
  164                Xrm.Page .getAttrib ute("owner id").setSu bmitMode(' always');
  165                //Set As signed to  Surrogate  to No
  166                Xrm.Page .getAttrib ute("tri_i ssurrogate assigned") .setValue( 0);
  167                Xrm.Page .getAttrib ute("tri_i ssurrogate assigned") .setSubmit Mode('alwa ys');
  168                rgs_owne rChange();
  169                return f alse;
  170           }
  171  
  172           // Check if V IA Login c ookie exis t (not exp ired)
  173           va r rgs_ViaL oginCookie  = rgs_get Cookie("vi asessionli nk");
  174  
  175           if  (rgs_ViaL oginCookie  == "") {
  176                alert("Y our VISTA  session ha s expired.  In order  to check f or surroga tes, you m ust be log ged into V ISTA!");
  177                Xrm.Page .ui.tabs.g et('Tab_Vi stALogin') .setVisibl e(true);
  178                Xrm.Page .ui.tabs.g et('Tab_Vi stALogin') .setFocus( );
  179                //Exit p rocess, cl ear notifi cation mes sage
  180                Xrm.Page .ui.clearF ormNotific ation("SUR R1001");
  181                Xrm.Page .getAttrib ute("ftp_u serselecte d").setVal ue(null);
  182                Xrm.Page .getAttrib ute("ftp_u serselecte d").setSub mitMode('a lways');
  183                return f alse;
  184           }
  185  
  186           // Prep user  data
  187           va r rgs_user SiteId = " ";
  188           va r rgs_User SiteNo = " ";
  189           va r rgs_duz  = "";
  190           va r rgs_prov idername =  "";
  191           va r rgs_user Data = rgs _getSingle EntityData Sync('Syst emUserSet' , 'ftp_Fac ilitySiteI d', Xrm.Pa ge.context .getUserId ());
  192           if  (rgs_user Data != nu ll) {
  193                if (rgs_ userData.d .ftp_Facil itySiteId  != null) {
  194                    rgs_ userSiteId  = rgs_use rData.d.ft p_Facility SiteId.Id;
  195                }
  196           }
  197           // Lookup the  Facility/ Site #
  198           if  (rgs_user SiteId !=  null && rg s_userSite Id != '')  {
  199                var rgs_ facilityDa ta = rgs_g etSingleEn tityDataSy nc('ftp_fa cilitySet' , 'ftp_fac ilitycode' , rgs_user SiteId);
  200                if (rgs_ facilityDa ta != null ) {
  201                    if ( rgs_facili tyData.d.f tp_facilit ycode != n ull) { rgs _UserSiteN o = rgs_fa cilityData .d.ftp_fac ilitycode;  }
  202                }
  203           }
  204  
  205           // Get VIA Lo gin Cookie  data
  206           va r rgs_ViaL oginCookie  = rgs_get Cookie("vi asessionli nk");
  207  
  208           if  (rgs_ViaL oginCookie  != null & & rgs_ViaL oginCookie  != '') {
  209                var rgs_ cookiearra y = rgs_Vi aLoginCook ie.split(" ~~~~", 2);
  210                rgs_duz  = rgs_cook iearray[0] ;
  211                rgs_prov idername =  rgs_cooki earray[1];
  212           }
  213  
  214           if  (rgs_cros sReference Duz == nul l && rgs_c rossRefere nceName !=  null && r gs_crossRe ferenceNam e != '') {
  215                //No IEN , but have  name, att empt cprs  User Looku p
  216                //Extrac t Last Nam e from VIS TA Name
  217                var rgs_ cprsSearch Name = nul l;
  218                //Split  on comma
  219                rgs_cprs SearchName  = rgs_cro ssReferenc eName.spli t(",", 1);
  220                //Split  on space
  221                rgs_cprs SearchName  = rgs_cpr sSearchNam e[0].split (" ", 1);
  222  
  223                //Prep e xternal ob ject for v ia service  use
  224                var rgs_ viaDataObj ect = new  Object();
  225                rgs_viaD ataObject. ProviderNa me = rgs_p rovidernam e;
  226                rgs_viaD ataObject. Duz = rgs_ duz;
  227                rgs_viaD ataObject. LoginSiteC ode = rgs_ UserSiteNo ;
  228                rgs_viaD ataObject. CrossRefNa me = rgs_c rossRefere nceName;
  229                
  230                //Execut e cprsUser Lookup Ser vice
  231                vialib_c prsUserLoo kup(rgs_re questingAp p, rgs_con sumingAppT oken, rgs_ consumingA ppPassword , rgs_base ServiceEnd pointUrl,  rgs_provid ername, rg s_duz, rgs _UserSiteN o, rgs_cpr sSearchNam e, rgs_cpr sUserLooku p_response , rgs_viaD ataObject) ;
  232  
  233           }
  234           if  (rgs_cros sReference Duz != nul l) {
  235                //Perfor m Surrogat e Check
  236                rgs_exec uteVistaGe tSurrogate (rgs_provi dername, r gs_duz, rg s_UserSite No, rgs_cr ossReferen ceDuz)
  237           }
  238           // Fallback i f no match , should n ot happen
  239           if  (rgs_cros sReference Duz == nul l && (rgs_ crossRefer enceName = = null ||  rgs_crossR eferenceNa me == ''))  {
  240                //Values  are null,  inform us er and per form stand ard assign ement and  exit
  241                var rgs_ userSelect edValue =  Xrm.Page.g etAttribut e("ftp_use rselected" ).getValue ();
  242                Xrm.Page .ui.setFor mNotificat ion("The s elected us er has an  incomplete  VIA/CRM C ross Refer ence recor d. A surro gate check  was not p erformed!" , "INFO",  "SURR1001" );
  243                Xrm.Page .getAttrib ute("owner id").setVa lue([{
  244                    id:  rgs_userSe lectedValu e[0].id,
  245                    name : rgs_user SelectedVa lue[0].nam e,
  246                    enti tyType: "s ystemuser"
  247                }]);
  248                Xrm.Page .getAttrib ute("owner id").setSu bmitMode(' always');
  249                //Set As signed to  Surrogate  to No
  250                Xrm.Page .getAttrib ute("tri_i ssurrogate assigned") .setValue( 0);
  251                Xrm.Page .getAttrib ute("tri_i ssurrogate assigned") .setSubmit Mode('alwa ys');
  252                rgs_owne rChange();
  253                return f alse;
  254           }
  255       }
  256       catch  (err) {
  257           al ert('Reque st Surroga te Functio n Error(rg s_viaSurro gateSettin g_response ): ' + err .message);
  258           Xr m.Page.ui. clearFormN otificatio n("SURR100 1");
  259       }
  260   }
  261  
  262   function r gs_execute VistaGetSu rrogate(rg s_provider name, rgs_ duz, rgs_U serSiteNo,  rgs_cross ReferenceD uz) {
  263       try {
  264           // Perform th e Surrogat e Lookup
  265           va r rgs_viaS urrogate =  new Objec t();
  266           rg s_viaSurro gate.Provi derName =  rgs_provid ername;
  267           rg s_viaSurro gate.Duz =  rgs_duz;
  268           rg s_viaSurro gate.Login SiteCode =  rgs_UserS iteNo;
  269           rg s_viaSurro gate.Targe t = rgs_cr ossReferen ceDuz;
  270  
  271           $. ajax({
  272                type: "P OST",
  273                url: rgs _GetSurrog ateUrl,
  274                data: JS ON.stringi fy(rgs_via Surrogate) ,
  275                contentT ype: "appl ication/js on; charse t=utf-8",
  276                dataType : "json",
  277                success:  function  (data) {
  278                    var  rgs_newdat a = data.D ata;
  279                    var  rgs_reques tResponse  = rgs_newd ata;
  280                    rgs_ executeVis taGetSurro gate_respo nse(null,  rgs_reques tResponse) ;
  281                },
  282                error: f unction (j qXHR, text Status, er rorThrown)  {
  283                    //Sy stem Error
  284                    rgs_ executeVis taGetSurro gate_respo nse(errorT hrown, nul l);
  285                },
  286                async: f alse,
  287                cache: f alse
  288           }) ;
  289       }
  290       catch  (err) {
  291           al ert('Reque st Surroga te Functio n Error(rg s_executeV istaGetSur rogate): '  + err.mes sage);
  292           Xr m.Page.ui. clearFormN otificatio n("SURR100 1");
  293       }
  294   }
  295  
  296   function r gs_cprsUse rLookup_re sponse(rgs _error, rg s_userlook upResponse , rgs_exte rnalObject ) {
  297       try {
  298           // Check for  non VIA Se rvice Erro r
  299           if  (rgs_erro r != null)  {
  300                alert("T he VIA cpr sUserLooku p service  failed wit h error: "  + rgs_use rlookupRes ponse);
  301                //Exit p rocess, cl ear notifi cation mes sage
  302                Xrm.Page .ui.clearF ormNotific ation("SUR R1001");
  303                Xrm.Page .getAttrib ute("ftp_u serselecte d").setVal ue(null);
  304                Xrm.Page .getAttrib ute("ftp_u serselecte d").setSub mitMode('a lways');
  305                return f alse;
  306           }
  307           // Test for V IA Service  Error
  308           if  (rgs_user lookupResp onse.getEl ementsByTa gName("fau lt").lengt h > 0) {
  309                alert("T he VIA cpr sUserLooku p service  failed wit h error: "  + rgs_use rlookupRes ponse.getE lementsByT agName("fa ult")[0].t extContent );
  310                //Exit p rocess, cl ear notifi cation mes sage
  311                Xrm.Page .ui.clearF ormNotific ation("SUR R1001");
  312                Xrm.Page .getAttrib ute("ftp_u serselecte d").setVal ue(null);
  313                Xrm.Page .getAttrib ute("ftp_u serselecte d").setSub mitMode('a lways');
  314                return f alse;
  315           }
  316  
  317           va r rgs_cprs UserIEN =  null;
  318           va r rgs_cprs MatchCount  = 0;
  319  
  320           // Get VIA se rvice Resp onse
  321           if  (rgs_user lookupResp onse.getEl ementsByTa gName("use rs")[0].ch ildNodes.l ength > 0)  {
  322                var rgs_ userlookup Array = rg s_userlook upResponse .getElemen tsByTagNam e("users") [0].childN odes;
  323  
  324                //Analyz e result
  325                for (var  i = 0; i  <= rgs_use rlookupArr ay.length  - 1; i++)  {              
  326                    //Co mpare VIA  Full Name  to the VIA  Full Name  in CRM an d if a mat ch, add to  list...
  327                    var  rgs_cprsUs erName = r gs_userloo kupArray[i ].childNod es[0].text Content;
  328                    var  rgs_cprsUs erNameUppe r = rgs_cp rsUserName .toUpperCa se();
  329                    var  rgs_crossR efName = r gs_externa lObject.Cr ossRefName ;
  330                    var  rgs_crossR efNameUppe r = rgs_cr ossRefName .toUpperCa se();
  331  
  332                    if ( rgs_cprsUs erNameUppe r == rgs_c rossRefNam eUpper) {
  333                         //User Nam es Match
  334                         rgs_cprsMa tchCount =  rgs_cprsM atchCount  + 1;
  335                         rgs_cprsUs erIEN = rg s_userlook upArray[i] .childNode s[1].textC ontent;
  336                    }
  337                }
  338           }
  339  
  340           //
  341           if  (rgs_cprs MatchCount  == 1 && r gs_cprsUse rIEN != nu ll) {
  342                //Perfor m Surrogat e Check
  343                rgs_exec uteVistaGe tSurrogate (rgs_exter nalObject. ProviderNa me, rgs_ex ternalObje ct.Duz, rg s_external Object.Log inSiteCode , rgs_cprs UserIEN)
  344           }
  345           el se {
  346                //Values  are null,  inform us er and per form stand ard assign ement and  exit
  347                var rgs_ userSelect edValue =  Xrm.Page.g etAttribut e("ftp_use rselected" ).getValue ();
  348                Xrm.Page .ui.setFor mNotificat ion("The s elected us er was not  located i n VIA/CPRS  or more t han one ex ist with t he same na me. A surr ogate chec k was not  performed! ", "INFO",  "SURR1001 ");
  349                Xrm.Page .getAttrib ute("owner id").setVa lue([{
  350                    id:  rgs_userSe lectedValu e[0].id,
  351                    name : rgs_user SelectedVa lue[0].nam e,
  352                    enti tyType: "s ystemuser"
  353                }]);
  354                Xrm.Page .getAttrib ute("owner id").setSu bmitMode(' always');
  355                //Set As signed to  Surrogate  to No
  356                Xrm.Page .getAttrib ute("tri_i ssurrogate assigned") .setValue( 0);
  357                Xrm.Page .getAttrib ute("tri_i ssurrogate assigned") .setSubmit Mode('alwa ys');
  358                rgs_owne rChange();
  359                return f alse;
  360           }
  361       }
  362       catch  (err) {
  363           al ert('Reque st Surroga te Functio n Error(rg s_cprsUser Lookup_res ponse): '  + err.mess age);
  364           Xr m.Page.ui. clearFormN otificatio n("SURR100 1");
  365       }
  366   }
  367  
  368   function r gs_execute VistaGetSu rrogate_re sponse(rgs _errorThro wn, rgs_re questRespo nse) {
  369       try {
  370           // Process Ge t Surrogat e Request  Response
  371           if  (rgs_erro rThrown !=  null) {
  372                //Handle  Error
  373                alert("T he VIA Get Surrogate  Service Fa iled with  error: " +  rgs_error Thrown);
  374                Xrm.Page .ui.clearF ormNotific ation("SUR R1001");
  375                return f alse;
  376           }
  377           el se {
  378                if (rgs_ requestRes ponse.leng th > 0) {
  379                    //Su rrogate Re turned, pr ocess data
  380                    var  rgs_surrog ateId = rg s_requestR esponse[0] .Id;
  381                    var  rgs_surrog ateName =  rgs_reques tResponse[ 0].Name;
  382                    var  rgs_surrog ateStartDa te = rgs_r equestResp onse[0].St artDate;
  383                    var  rgs_surrog ateEndDate  = rgs_req uestRespon se[0].EndD ate;
  384  
  385                    //Po pulate Sur rogate Ass ignee Fiel d
  386                    Xrm. Page.getAt tribute("f tp_surroga teassignee ").setValu e(rgs_surr ogateName) ;
  387                    Xrm. Page.getAt tribute("f tp_surroga teassignee ").setSubm itMode('al ways');
  388                    //Se t Assigned  to Surrog ate to Yes
  389                    Xrm. Page.getAt tribute("t ri_issurro gateassign ed").setVa lue(1);
  390                    Xrm. Page.getAt tribute("t ri_issurro gateassign ed").setSu bmitMode(' always');
  391                    //Di splay surr ogate assi gned to us er
  392                    Xrm. Page.ui.se tFormNotif ication("A  surrogate  user '" +  rgs_surro gateName +  "' was ap plied!", " INFO", "SU RR1001");
  393                    //Up date the o wner field ...
  394                    var  rgs_userSe lectedValu e = Xrm.Pa ge.getAttr ibute("ftp _userselec ted").getV alue();
  395                    Xrm. Page.getAt tribute("o wnerid").s etValue([{
  396                         id: rgs_us erSelected Value[0].i d,
  397                         name: rgs_ userSelect edValue[0] .name,
  398                         entityType : "systemu ser"
  399                    }]);
  400                    Xrm. Page.getAt tribute("o wnerid").s etSubmitMo de('always ');
  401                    rgs_ ownerChang e();
  402                    retu rn false;
  403  
  404  
  405                    //** *The Secti on below i s the prio r method o f assignin g surrogat es
  406                    //** *Code is c ommented o ut, but ma y be used  again late r..
  407                    /*
  408                    //De termine if  CRM Cross  Reference  has a rec ord for th is IEN/Id
  409                    var  rgs_crossR eferenceId  = null;
  410                    var  rgs_crossR eferenceCr mUser = nu ll;
  411                    var  rgs_condit ionalFilte r = "ftp_v istaduz eq  '" + rgs_ surrogateI d + "'";
  412                    var  rgs_crossR eferenceDa ta = rgs_g etMultiple EntityData Sync('ftp_ useridSet' , 'ftp_use ridId, ftp _crmuser',  rgs_condi tionalFilt er, 'ftp_n ame', 'asc ', 0);
  413                    if ( rgs_crossR eferenceDa ta != null ) {
  414                         for (var i  = 0; i <=  rgs_cross ReferenceD ata.d.resu lts.length  - 1; i++)  {
  415                             //Get  Info
  416                             if (rg s_crossRef erenceData .d.results [i].ftp_us eridId !=  null) { rg s_crossRef erenceId =  rgs_cross ReferenceD ata.d.resu lts[i].ftp _useridId;  }
  417                             if (rg s_crossRef erenceData .d.results [i].ftp_cr muser != n ull) { rgs _crossRefe renceCrmUs er = rgs_c rossRefere nceData.d. results[i] .ftp_crmus er; }
  418                             break;
  419                         }
  420                    }
  421  
  422                    if ( rgs_crossR eferenceCr mUser != n ull) {
  423                         //Cross Re ference fo r Surrogat e Exists
  424                         Xrm.Page.u i.setFormN otificatio n("A surro gate user  '" + rgs_s urrogateNa me + "' wa s assigned !", "INFO" , "SURR100 1");
  425                         //Set the  selected u ser as the  Original  Assignee
  426                         var rgs_us erSelected Value = Xr m.Page.get Attribute( "ftp_users elected"). getValue() ;
  427                         Xrm.Page.g etAttribut e("tri_ori ginalassig nee").setV alue([{
  428                             id: rg s_userSele ctedValue[ 0].id,
  429                             name:  rgs_userSe lectedValu e[0].name,
  430                             entity Type: "sys temuser"
  431                         }]);
  432                         Xrm.Page.g etAttribut e("tri_ori ginalassig nee").setS ubmitMode( 'always');
  433  
  434                         //Set the  owner to t he Surroga te user
  435                         Xrm.Page.g etAttribut e("ownerid ").setValu e([{
  436                             id: rg s_crossRef erenceCrmU ser.Id,
  437                             name:  rgs_crossR eferenceCr mUser.Name ,
  438                             entity Type: "sys temuser"
  439                         }]);
  440                         Xrm.Page.g etAttribut e("ownerid ").setSubm itMode('al ways');
  441                         //Set Assi gned to Su rrogate to  Yes
  442                         Xrm.Page.g etAttribut e("tri_iss urrogateas signed").s etValue(1) ;
  443                         Xrm.Page.g etAttribut e("tri_iss urrogateas signed").s etSubmitMo de('always ');
  444  
  445                         rgs_ownerC hange();
  446  
  447                         //Set the  selected u ser to the  surrogate  user
  448                         Xrm.Page.g etAttribut e("ftp_use rselected" ).setValue ([{
  449                             id: rg s_crossRef erenceCrmU ser.Id,
  450                             name:  rgs_crossR eferenceCr mUser.Name ,
  451                             entity Type: "sys temuser"
  452                         }]);
  453                         Xrm.Page.g etAttribut e("ftp_use rselected" ).setSubmi tMode('alw ays');
  454  
  455                         return fal se;
  456                    }
  457                    else  {
  458                         //No match ing surrog ate User I n CRM
  459                         Xrm.Page.u i.setFormN otificatio n("The sur rogate use r '" + rgs _surrogate Name + "'  does not h ave a VIA/ CRM Cross  Reference  record. Th e selected  user was  used inste ad!", "INF O", "SURR1 001");
  460                         var rgs_us erSelected Value = Xr m.Page.get Attribute( "ftp_users elected"). getValue() ;
  461                         Xrm.Page.g etAttribut e("ownerid ").setValu e([{
  462                             id: rg s_userSele ctedValue[ 0].id,
  463                             name:  rgs_userSe lectedValu e[0].name,
  464                             entity Type: "sys temuser"
  465                         }]);
  466                         Xrm.Page.g etAttribut e("ownerid ").setSubm itMode('al ways');
  467                         //Set Assi gned to Su rrogate to  No
  468                         Xrm.Page.g etAttribut e("tri_iss urrogateas signed").s etValue(0) ;
  469                         Xrm.Page.g etAttribut e("tri_iss urrogateas signed").s etSubmitMo de('always ');
  470                         rgs_ownerC hange();
  471                         return fal se;
  472                    }
  473                    */
  474                    //** *End of co mmented ou t section  for reuse  later
  475  
  476                }
  477                else {
  478                    //No  Surrogate  Returned,  complete  assign wit h current  selection
  479                    var  rgs_userSe lectedValu e = Xrm.Pa ge.getAttr ibute("ftp _userselec ted").getV alue();
  480                    Xrm. Page.getAt tribute("o wnerid").s etValue([{
  481                         id: rgs_us erSelected Value[0].i d,
  482                         name: rgs_ userSelect edValue[0] .name,
  483                         entityType : "systemu ser"
  484                    }]);
  485                    Xrm. Page.getAt tribute("o wnerid").s etSubmitMo de('always ');
  486                    //Se t Assigned  to Surrog ate to No
  487                    Xrm. Page.getAt tribute("t ri_issurro gateassign ed").setVa lue(0);
  488                    Xrm. Page.getAt tribute("t ri_issurro gateassign ed").setSu bmitMode(' always');
  489                    rgs_ ownerChang e();
  490                }
  491                //Clear  progress m essages
  492                Xrm.Page .ui.clearF ormNotific ation("SUR R1001");
  493           }
  494       }
  495       catch  (err) {
  496           al ert('Reque st Surroga te Functio n Error(rg s_executeV istaGetSur rogate_res ponse): '  + err.mess age);
  497           Xr m.Page.ui. clearFormN otificatio n("SURR100 1");
  498       }
  499   }
  500  
  501   function r gs_ownerCh ange() {
  502       try {
  503           Xr m.Page.get Attribute( "ownerid") .fireOnCha nge();
  504       }
  505       catch  (err) {
  506           al ert('Reque st Surroga te Functio n Error(rg s_ownerCha nge): ' +  err.messag e);
  507       }
  508   }
  509  
  510   function r gs_getCook ie(cname)  {
  511       try {
  512           va r name = c name + "=" ;
  513           va r ca = doc ument.cook ie.split(' ;');
  514           fo r (var i =  0; i < ca .length; i ++) {
  515                var c =  ca[i];
  516                while (c .charAt(0)  == ' ') {
  517                    c =  c.substrin g(1);
  518                }
  519                if (c.in dexOf(name ) == 0) {
  520                    retu rn c.subst ring(name. length, c. length);
  521                }
  522           }
  523           re turn "";
  524       }
  525       catch  (err) {
  526           al ert('Reque st Surroga te Functio n Error(rg s_getCooki e): ' + er r.message) ;
  527       }
  528   }
  529  
  530   function r gs_decrypt ServiceCon nector(rgs _connector Array, rgs _connector Value) {
  531       var rg s_decrypte dString =  "";
  532       if (rg s_connecto rArray !=  null && rg s_connecto rArray !=  "") {
  533           va r rgs_newA rray = rgs _connector Array.toSt ring().spl it(',');
  534           rg s_newArray .reverse() ;
  535           fo r (i = 0;  i < rgs_ne wArray.len gth; i++)  {
  536                var rgs_ curChar =  "";
  537                if (i ==  0) {
  538                    rgs_ curChar =  rgs_newArr ay[i] - rg s_connecto rValue;
  539                }
  540                else {
  541                    rgs_ curChar =  rgs_newArr ay[i] - (i  + rgs_con nectorValu e);
  542                }
  543                rgs_decr yptedStrin g = rgs_de cryptedStr ing + Stri ng.fromCha rCode(rgs_ curChar);
  544           }
  545       }
  546       return  rgs_decry ptedString ;
  547   }
  548  
  549   function r gs_execute CrmOdataGe tRequest(r gs_jsonQue ry, rgs_aS ync, rgs_a SyncCallba ck, rgs_sk ipCount, r gs_optionA rray) {
  550       //This  function  executes a  CRM Odata  web servi ce call to  retrieve  Crm data
  551       //*rgs _jsonQuery * - a prop erly forma tted CRM O data Query  string (r equired)
  552       //*rgs _aSync* -  specify 't rue' to ex ecute asyn chronously  otherwise  'false' ( required)
  553       //*rgs _aSyncCall back* - sp ecify the  name of th e return f unction to  call upon  completio n (require d if rgs_a Sync = tru e.  Otherw ise '')
  554       //*rgs _skipCount * - Initia l setting  is always  '0', incre ments by 5 0 per CRM  SDK Odata  standards  (required)
  555       //*rgs _optionArr ay* - is a n optional  array or  single val ue, that c ontains ad ditional t ask specif ic variabl es that ca n be passe d between  functions  (pass 'nul l' if not  used)
  556       try {
  557           va r rgs_enti tyData = n ull;
  558           $. ajax({
  559                type: 'G ET',
  560                contentT ype: 'appl ication/js on; charse t=utf-8',
  561                datatype : 'json',
  562                url: rgs _jsonQuery ,
  563                beforeSe nd: functi on (XMLHtt pRequest)  {
  564                    XMLH ttpRequest .setReques tHeader('A ccept', 'a pplication /json');
  565                },
  566                success:  function  (data, tex tStatus, X mlHttpRequ est) {
  567                    rgs_ entityData  = data;
  568                    if ( rgs_aSync  == true) {
  569                         rgs_aSyncC allback(rg s_entityDa ta, rgs_sk ipCount, r gs_optionA rray);
  570                    }
  571                },
  572                error: f unction (X MLHttpRequ est, textS tatus, err orThrown)  {
  573                    aler t('Fail: A jax Error  in rgs_exe cuteCrmOda taGetReque st: ' + er rorThrown  + " Reques t: " + rgs _jsonQuery );
  574                },
  575                async: r gs_aSync,
  576                cache: f alse
  577           }) ;
  578           re turn rgs_e ntityData;
  579       }
  580       catch  (err) {
  581           al ert('An er ror occure d in the r gs_execute CrmOdataGe tRequest f unction.   Error Deta il Message : ' + err) ;
  582       }
  583   }
  584  
  585   function r gs_getMult ipleEntity DataAsync( rgs_entity SetName, r gs_attribu teSet, rgs _condition alFilter,  rgs_sortAt tribute, r gs_sortDir ection, rg s_skipCoun t, rgs_aSy ncCallback , rgs_opti onArray) {
  586       //This  function  returns a  CRM JSON d ataset for  all entit y records  matching c riteria pr ovided Asy ncronously
  587       //*rgs _entitySet Name* - is  the name  of the ent ity set e. g 'Contact Set'
  588       //*rgs _attribute Set* -  is  a string  containing  the Crm A ttributes  to retriev e e.g. 'Fi rstName, L astName, T elephone1,  EMailAddr ess1'
  589       //*rgs _condition alFilter*  - is the c onditional  filter va lue placed  on the da ta values  retrived e .g. 'State Code/Value  eq 0'  to  retrieve  active con tact recor ds only
  590       //*rgs _sortAttri bute* - is  a string  containing  the name  of the att ribute to  sort the r esult set  by e.g. 'L astName'
  591       //*rgs _sortDirec tion* - is  a string  specifying  the sort  as Ascendi ng or Desc ending e.g . 'asc' or  'desc'
  592       //*rgs _skipCount * - is the  starting  point in t he result  (use if mo re than 50 ), (Put 0  if not use d)
  593       //*rgs _aSyncCall back* - is  the name  of the fun ction to c all when r eturning t he result
  594       //*rgs _optionArr ay* - is a n optional  array, th at contain s addition al task sp ecific var iables tha t can be p assed betw een functi ons
  595  
  596       try {
  597           va r rgs_json Query = rg s_serverUr l + rgs_cr mOdataEndP oint + '/'  + rgs_ent itySetName  + '?$sele ct=' + rgs _attribute Set + '&$f ilter=' +  rgs_condit ionalFilte r + '&$ord erby=' + r gs_sortAtt ribute + '  ' + rgs_s ortDirecti on + '&$sk ip=' + rgs _skipCount ;
  598           rg s_executeC rmOdataGet Request(rg s_jsonQuer y, true, r gs_aSyncCa llback, rg s_skipCoun t, rgs_opt ionArray);
  599       }
  600       catch  (err) {
  601           al ert('An er ror occure d in the r gs_getMult ipleEntity DataAsync  function.   Error Det ail Messag e: ' + err );
  602       }
  603   }
  604  
  605   function r gs_getMult ipleEntity DataSync(r gs_entityS etName, rg s_attribut eSet, rgs_ conditiona lFilter, r gs_sortAtt ribute, rg s_sortDire ction, rgs _skipCount ) {
  606       //This  function  returns a  CRM JSON d ataset for  all entit y records  matching c riteria pr ovided Syn cronously
  607       //*rgs _entitySet Name* - is  the name  of the ent ity set e. g 'Contact Set'
  608       //*rgs _attribute Set* -  is  a string  containing  the Crm A ttributes  to retriev e e.g. 'Fi rstName, L astName, T elephone1,  EMailAddr ess1'
  609       //*rgs _condition alFilter*  - is the c onditional  filter va lue placed  on the da ta values  retrived e .g. 'State Code/Value  eq 0'  to  retrieve  active con tact recor ds only
  610       //*rgs _sortAttri bute* - is  a string  containing  the name  of the att ribute to  sort the r esult set  by e.g. 'L astName'
  611       //*rgs _sortDirec tion* - is  a string  specifying  the sort  as Ascendi ng or Desc ending e.g . 'asc' or  'desc'
  612       //*rgs _skipCount * - is the  starting  point in t he result  (use if mo re than 50 ), (Put 0  if not use d)
  613  
  614       try {
  615           va r rgs_json Query = rg s_serverUr l + rgs_cr mOdataEndP oint + '/'  + rgs_ent itySetName  + '?$sele ct=' + rgs _attribute Set + '&$f ilter=' +  rgs_condit ionalFilte r + '&$ord erby=' + r gs_sortAtt ribute + '  ' + rgs_s ortDirecti on + '&$sk ip=' + rgs _skipCount ;
  616           va r rgs_enti tyData = r gs_execute CrmOdataGe tRequest(r gs_jsonQue ry, false,  '', rgs_s kipCount,  null);
  617           re turn rgs_e ntityData;
  618       }
  619       catch  (err) {
  620           al ert('An er ror occure d in the r gs_getMult ipleEntity DataSync f unction.   Error Deta il Message : ' + err) ;
  621       }
  622   }
  623  
  624   function r gs_getSing leEntityDa taSync(rgs _entitySet Name, rgs_ attributeS et, rgs_en tityId) {
  625       //This  function  returns a  CRM JSON d ataset for  a single  entity rec ord based  on the ent ity id pro vided Sync ronously
  626       //*rgs _entitySet Name* - is  the name  of the ent ity set e. g 'Contact Set'
  627       //*rgs _attribute Set* -  is  a string  containing  the Crm A ttributes  to retriev e e.g. 'Fi rstName, L astName, T elephone1,  EMailAddr ess1'
  628       //*rgs _entityId*  - is the  Guid for t he entity  record
  629  
  630       try {
  631           va r rgs_enti tyIdNoBrac ket = rgs_ entityId.r eplace(/({ |})/g, '') ;
  632           va r rgs_sele ctString =  '(guid' +  "'" + rgs _entityIdN oBracket +  "'" + ')? $select='  + rgs_attr ibuteSet;
  633           va r rgs_json Query = rg s_serverUr l + rgs_cr mOdataEndP oint + '/'  + rgs_ent itySetName  + rgs_sel ectString;
  634           va r rgs_enti tyData = r gs_execute CrmOdataGe tRequest(r gs_jsonQue ry, false,  '', 0, nu ll);
  635           re turn rgs_e ntityData;
  636       }
  637       catch  (err) {
  638           al ert('An er ror occure d in the r gs_getSing leEntityDa taSync fun ction.  Er ror Detail  Message:  ' + err);
  639       }
  640   }