locked
copy the string values of the standard attribute to a custom field RRS feed

  • Question

  • Hi all,

    I am trying to copy the string values of the standard attribute to a custom field. I want "Required Attendees" into a different field but I am stuck with my code. Would anyone be able to take a peak where am I going wrong here? Any feedback would be much appreciated!

    function getPartyList() {

                var partyRequired = Xrm.Page.getAttribute(“requiredattendees”);

                var attendees = partyRequired.getValue();

               

                var strContacts = "";

                var strUsers = "";

               

                for (var indxAttendees = 0; indxAttendees < attendees.length; indxAttendees++) {

                            // User

                            if (attendees[indxAttendees].type == 8) {

                                        alert(“Attendee is User; Id -” + attendees[indxAttendees].id + ” Name -” + attendees[indxAttendees].name);

                                        strUsers += ", " + attendees[indxAttendees].name;

                            }

                            // Contact

                            if (attendees[indxAttendees].type == 2) {

                                        alert(“Attendee is Contact; Id -” + attendees[indxAttendees].id + ” Name -” + attendees[indxAttendees].name);

                                        strContacts += ", " + attendees[indxAttendees].name;                           

                            }

                }

                Xrm.Page.getAttribute("new_requiredattendeestext").setValue("Contacts: " + strContacts "; Users: " + strUsers);

    }

    Thursday, April 10, 2014 9:23 PM

All replies

  • you are checking a "type" property, but that property doesn't exist, you need to use entityType

    try with:

    function getPartyList() {
       var partyRequired = Xrm.Page.getAttribute(“requiredattendees”);
       var attendees = partyRequired.getValue();
    
       var strContacts = "";
       var strUsers = "";
    
       for (var indxAttendees = 0; indxAttendees < attendees.length; indxAttendees++) {
          // User
          if (attendees[indxAttendees].entityType == "systemuser") {
             alert("Attendee is User; Id -" + attendees[indxAttendees].id + " Name -" + attendees[indxAttendees].name);
             strUsers += ", " + attendees[indxAttendees].name;
          }
    
          // Contact
          if (attendees[indxAttendees].entityType == "contact") {
             alert("Attendee is Contact; Id -" + attendees[indxAttendees].id + " Name -" + attendees[indxAttendees].name);
             strContacts += ", " + attendees[indxAttendees].name;
          }
       }
       
       Xrm.Page.getAttribute("new_requiredattendeestext").setValue("Contacts: " + strContacts + "; Users: " + strUsers);
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile




    Thursday, April 10, 2014 10:28 PM
  • Hi Guido, thanks for above but I still get an error. Am I missing something else here?

    "there was an error with this field's customized event"

    Field: window

    Event: onload

    Error: undefined

    and then it also generates this error log

    Microsoft Dynamics CRM Error Report Contents

    <CrmScriptErrorReport>
      <ReportVersion>1.0</ReportVersion>
      <ScriptErrorDetails>
       <Message>Uncaught SyntaxError: Unexpected token ILLEGAL</Message>
       <Line>3</Line>
       <URL>/%7B635327777660000050%7D/WebResources/new_getrequiredattendees</URL>
       <PageURL>/main.aspx?etc=4201&extraqs=%3f_CreateFromId%3d%257b94CB6894-FFB8-E311-94D6-6C3BE5A87530%257d%26_CreateFromType%3d1%26_gridType%3d4201%26etc%3d4201%26id%3d%257b20EB7A08-DDBA-E311-94D6-6C3BE5A87530%257d%26rskey%3d655715710&pagemode=iframe&pagetype=entityrecord&rskey=655715710</PageURL>
       <Function>anonymousror:UnexpectedtokenILLEGAL</Function>
       <CallStack>
        <Function>anonymousror:UnexpectedtokenILLEGAL</Function>
       </CallStack>
      </ScriptErrorDetails>
      <ClientInformation>
       <BrowserUserAgent>Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36</BrowserUserAgent>
       <BrowserLanguage>undefined</BrowserLanguage>
       <SystemLanguage>undefined</SystemLanguage>
       <UserLanguage>undefined</UserLanguage>
       <ScreenResolution>1600x900</ScreenResolution>
       <ClientName>Web</ClientName>
       <ClientTime>2014-04-10T21:59:42</ClientTime>
      </ClientInformation>
      <ServerInformation>
        <OrgLanguage>1033</OrgLanguage>
        <OrgCulture>1033</OrgCulture>
        <UserLanguage>1033</UserLanguage>
        <UserCulture>1033</UserCulture>
        <OrgID>{F709FC5E-2936-4248-B292-E6777FBAD269}</OrgID>
        <UserID>{10BF336A-B313-4870-B31A-940A40CF2969}</UserID>
        <CRMVersion>6.0.2.50</CRMVersion>
      </ServerInformation>
    </CrmScriptErrorReport>

    • Edited by Donyc Friday, April 11, 2014 2:01 AM
    Friday, April 11, 2014 1:57 AM
  • As found in your post in Dynamics Community, a plus sign is missing in your last row:

    Xrm.Page.getAttribute("new_requiredattendeestext").setValue("Contacts: " + strContacts  + "; Users: " + strUsers);


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Friday, April 11, 2014 8:01 AM
  • Thanks everyone for your feedback but I am still getting this darn error msg! I updated the code as per below, no idea what is the issue now then

    function getPartyList() {

      var partyRequired = Xrm.Page.getAttribute(“requiredattendees”);

      var attendees = partyRequired.getValue();

      var strContacts = "";

      var strUsers = "";

      for (var indxAttendees = 0; indxAttendees < attendees.length; indxAttendees++) {

         // User

         if (attendees[indxAttendees].entityType == "systemuser") {

            alert("Attendee is User; Id -" + attendees[indxAttendees].id + " Name -" + attendees[indxAttendees].name);

            strUsers += ", " + attendees[indxAttendees].name;

         }

         // Contact

         if (attendees[indxAttendees].entityType == "contact") {

            alert("Attendee is Contact; Id -" + attendees[indxAttendees].id + " Name -" + attendees[indxAttendees].name);

            strContacts += ", " + attendees[indxAttendees].name;

         }

      }

    Xrm.Page.getAttribute("new_requiredattendeestext").setValue("Contacts: " + strContacts  + "; Users: " + strUsers);
    }

    Friday, April 11, 2014 11:15 AM
  • Hi Donyc,

    my guess is that this kind of error comes if you got invalid javascript character in your code for example ” character is not recognized in Jscript it should be replaced with " or ' character.

    to resolve this best thing to do is copy whole function code in to notepad and then put one line at time in code in your java script function to see if which line causes this issue once you found that then this line should be rewritten completely with supported characters and it will resolve your issue..

    hope this helps..


    MayankP
    My Blog
    Follow Me on Twitter

    Friday, April 11, 2014 11:35 AM
    Answerer
  • Hi MayankP, so I tried with just one line and I still got the error.. When you say line by line, is there anything around the line I need to keep? I tried with:

    function getPartyList() {

      var partyRequired = Xrm.Page.getAttribute(“requiredattendees”);

    }

    full code is, ones in red is what I left to try

    function getPartyList() {

      var partyRequired = Xrm.Page.getAttribute(“requiredattendees”);

      var attendees = partyRequired.getValue();

      var strContacts = "";

      var strUsers = "";

      for (var indxAttendees = 0; indxAttendees < attendees.length; indxAttendees++) {

         // User

         if (attendees[indxAttendees].entityType == "systemuser") {

            alert("Attendee is User; Id -" + attendees[indxAttendees].id + " Name -" + attendees[indxAttendees].name);

            strUsers += ", " + attendees[indxAttendees].name;

         }

         // Contact

         if (attendees[indxAttendees].entityType == "contact") {

            alert("Attendee is Contact; Id -" + attendees[indxAttendees].id + " Name -" + attendees[indxAttendees].name);

            strContacts += ", " + attendees[indxAttendees].name;

         }

      }

    Xrm.Page.getAttribute("new_requiredattendeestext").setValue("Contacts: " + strContacts  + "; Users: " + strUsers);
    }

    Friday, April 11, 2014 12:03 PM