sparkymark75
sparkymark75

Reputation: 593

Setting a PartyList value isn't being resolved correctly

I have some Javascript attached to the Service Activity form which fires OnLoad. It retrieves the TechId associated with the Service Case (which is related to the Service Activity) and tries to set the resource for the Service Activity to this user by default.

Screenshot of the unresolved resource

As you can see in the screenshot above, it inserts the correct "name" into the Resources field but it doesn't seem to resolve it properly as the icon is "corrupt". If I remove this and manually add the same user, everything is ok. If I try and save this activity as it is in the image, I get an error generated which points to the scheduling engine having problems.

The code I use to set this value is;

function SetTechId()
{
if (Xrm.Page.getAttribute("resources").getValue() == null)
{
    if (Xrm.Page.getAttribute("regardingobjectid").getValue() != null)
    {
        var caseId = Xrm.Page.getAttribute("regardingobjectid").getValue()[0].id;

        var endPoint = getODataEndPoint();
        var odataSelect = endPoint + "/IncidentSet?$select=new_new_fieldtechs_incident/OwnerId,new_new_fieldtechs_incident/OwningUser&$expand=new_new_fieldtechs_incident&$filter=IncidentId eq guid'" +  caseId + "'";

        $.ajax({
               type: "GET",
               contentType: "application/json; charset=utf-8",
               datatype: "json",
               url: odataSelect,
               beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
               success: function (data, textStatus, XmlHttpRequest) 
                   {
                        if (data.d != null)
                        {
                            var fieldTech = data.d.results[0];
                            var ownerId = fieldTech.new_new_fieldtechs_incident.OwnerId;

                            //because the resources field in the service activity is a partylist, we need to treat this differently
                            var partylist = new Array();
                            partylist[0] = new Object();
                            partylist[0].id = ownerId.Id; //Guid (i.e., Guid of User or Contact etc)
                            partylist[0].name = ownerId.Name; //Name (i.e., Name of User or Contact etc)
                            partylist[0].entityType = "account"; //entity schema name of account or contact

                            Xrm.Page.getAttribute("resources").setValue(partylist);
                        }
                   },
               error: function (XmlHttpRequest, textStatus, errorThrown) { }
        });
    }
}
}

function getODataEndPoint() {
return Xrm.Page.context.prependOrgName("/xrmservices/2011/OrganizationData.svc"); 
};

Upvotes: 1

Views: 1580

Answers (1)

Greg Owens
Greg Owens

Reputation: 3878

Is "Tony Harley" really an account or is it a systemuser?

partylist[0].entityType = "account"; //entity schema name of account or contact

Upvotes: 4

Related Questions