locked
CRM 2013- Fields Not Populating RRS feed

  • Question

  • I am using jScript to write a function that will populate a field from the resource.   have used this code before in 2011 and it 2013 it seems like the code works but on the form when I look at the field it does not show the value.  When I hover over it I can see the correct value and to insert it I must select it.  This code is onLoad and is supposed to automatically populate the field.  Below is the code I am using.  Has anyone come across this issue before or seen anything like it?  Thanks. 

    function setResourceLookupCurrentUser(pDestField) {

        //set global variable to parameter for resource field

        vDestField = pDestField;

        //Variable to Collect

        this.User = "unmodified";

        this.Resource = "unmodified";

     

        // Check if Lookup field is null

        if (Xrm.Page.getAttribute(vDestField).getValue() == null) {

            getUser();

        }

    }

     

        function getUser() {

            //Store Current User GUID

            var UserGUID = Xrm.Page.context.getUserId();

     

            //Variable to store OData Query

            var UserQuery = "$select=FirstName,MiddleName,LastName&$filter=SystemUserId eq guid'" + UserGUID + "'";

     

            SDK.REST.retrieveMultipleRecords(

            "SystemUser",

            UserQuery,

            function (results) {

                this.User = results[0];

            },

            function display(input) {

                alert("Error on Get User");

            },

        ////Function to get the resource record based on the current users GUID

          

     function getResource() {

     

                //Variable to store the full name

                var ResourceFirstName = this.User.FirstName;

                var ResourceMiddleName = this.User.MiddleName;

                var ResourceLastName = this.User.LastName;

     

                if (ResourceMiddleName != null) {

                    //Variable to stored OData Query

                    var ResourceQuery = "$select=hbs_pa_ResourceID,hbs_ResourceId&$filter=hbs_nv_FirstName eq '" + ResourceFirstName + "' and hbs_nv_MiddleName eq '" + ResourceMiddleName + "' and hbs_nv_LastName eq '" + ResourceLastName + "'&$top=1";

                }

                else if (ResourceMiddleName == null) {

                    var ResourceQuery = "$select=hbs_pa_ResourceID,hbs_ResourceId&$filter=hbs_nv_FirstName eq '" + ResourceFirstName + "' and hbs_nv_LastName eq '" + ResourceLastName + "'&$top=1";

                }

                SDK.REST.retrieveMultipleRecords(

                    "hbs_Resource",

                    ResourceQuery,

                    function (results) {

                        this.Resource = results[0];

                    },

                    function display(input) {

                        alert("Error on Get Resource");

                    },

     

                        ////Function to set the resource lookup

                    function setResource() {

     

                        //Set the id, typename, and name properties to the object.

                        var Resource = []

                        Resource[0] = {};

                        Resource[0].id = this.Resource.hbs_ResourceID;

                        Resource[0].entityType = "hbs_Resource";

                        Resource[0].name = this.Resource.hbs_pa_ResourceID;

                        Xrm.Page.getAttribute(vDestField).setValue(Resource);

                    }

                    )

            })

        }

    Thursday, November 21, 2013 4:21 PM