locked
Assign Record to a Team/User by Javascript RRS feed

  • Question

  • Hi, does any one has any working solution which assign a record to a team/user by using Soap/Javascript. I'm using the following link, but it is not working for CRM 2011

    thanks


    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, February 6, 2014 1:18 AM

Answers

  • Hi ,

    You can use the below JavaScript for assigning a record to team or user.

    //For User var UsedID = 'User id to be Assigned'; var UserName = 'user name'; Xrm.Page.getAttribute("ownerid").setValue([{ id: UsedID, name: UserName, entityType: "systemuser" }]);

    //For team var TeamID = 'Team id to be Assigned'; var TeamName = 'Team name'; Xrm.Page.getAttribute("ownerid").setValue([{ id: TeamID, name: TeamName, entityType: "team" }]);

    Regards,

    Priya


    • Proposed as answer by PriyaSwain Thursday, February 6, 2014 4:33 AM
    • Edited by PriyaSwain Thursday, February 6, 2014 4:59 AM
    • Marked as answer by Litonn Thursday, February 6, 2014 6:17 PM
    Thursday, February 6, 2014 4:33 AM
  • Try this - you'll need to set the Target id and type (record to be assigned) as well as the Assignee id and type (systemuser or team)

    var request = [];
    request.push('<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">\n');
    request.push('	<s:Body>\n');
    request.push('		<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">\n');
    request.push('			<request i:type="b:AssignRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">\n');
    request.push('				<a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">\n');
    request.push('					<a:KeyValuePairOfstringanyType>\n');
    request.push('						<c:key>Target</c:key>\n');
    request.push('						<c:value i:type="a:EntityReference">\n');
    request.push('							<a:Id>adba2236-b57f-e311-bb6d-6c3be5a881a4</a:Id>\n');
    request.push('							<a:LogicalName>account</a:LogicalName>\n');
    request.push('							<a:Name i:nil="true" />\n');
    request.push('						</c:value>\n');
    request.push('					</a:KeyValuePairOfstringanyType>\n');
    request.push('					<a:KeyValuePairOfstringanyType>\n');
    request.push('						<c:key>Assignee</c:key>\n');
    request.push('						<c:value i:type="a:EntityReference">\n');
    request.push('							<a:Id>fc099ce9-78b0-4273-b921-c72e010b308f</a:Id>\n');
    request.push('							<a:LogicalName>systemuser</a:LogicalName>\n');
    request.push('							<a:Name i:nil="true" />\n');
    request.push('						</c:value>\n');
    request.push('					</a:KeyValuePairOfstringanyType>\n');
    request.push('				</a:Parameters>\n');
    request.push('				<a:RequestId i:nil="true" />\n');
    request.push('				<a:RequestName>Assign</a:RequestName>\n');
    request.push('			</request>\n');
    request.push('		</Execute>\n');
    request.push('	</s:Body>\n');
    request.push('</s:Envelope>\n');
    
    var req = new XMLHttpRequest();
    req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", true);
    
    try {
        req.responseType = 'msxml-document';
    } catch (e) {}
    req.setRequestHeader("Accept", "application/xml, text/xml, */*");
    req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
    req.onreadystatechange = function () {};
    req.send(request.join(""));


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Thursday, February 6, 2014 4:45 AM
    Moderator

All replies

  • Hi ,

    You can use the below JavaScript for assigning a record to team or user.

    //For User var UsedID = 'User id to be Assigned'; var UserName = 'user name'; Xrm.Page.getAttribute("ownerid").setValue([{ id: UsedID, name: UserName, entityType: "systemuser" }]);

    //For team var TeamID = 'Team id to be Assigned'; var TeamName = 'Team name'; Xrm.Page.getAttribute("ownerid").setValue([{ id: TeamID, name: TeamName, entityType: "team" }]);

    Regards,

    Priya


    • Proposed as answer by PriyaSwain Thursday, February 6, 2014 4:33 AM
    • Edited by PriyaSwain Thursday, February 6, 2014 4:59 AM
    • Marked as answer by Litonn Thursday, February 6, 2014 6:17 PM
    Thursday, February 6, 2014 4:33 AM
  • Try this - you'll need to set the Target id and type (record to be assigned) as well as the Assignee id and type (systemuser or team)

    var request = [];
    request.push('<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">\n');
    request.push('	<s:Body>\n');
    request.push('		<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">\n');
    request.push('			<request i:type="b:AssignRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">\n');
    request.push('				<a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">\n');
    request.push('					<a:KeyValuePairOfstringanyType>\n');
    request.push('						<c:key>Target</c:key>\n');
    request.push('						<c:value i:type="a:EntityReference">\n');
    request.push('							<a:Id>adba2236-b57f-e311-bb6d-6c3be5a881a4</a:Id>\n');
    request.push('							<a:LogicalName>account</a:LogicalName>\n');
    request.push('							<a:Name i:nil="true" />\n');
    request.push('						</c:value>\n');
    request.push('					</a:KeyValuePairOfstringanyType>\n');
    request.push('					<a:KeyValuePairOfstringanyType>\n');
    request.push('						<c:key>Assignee</c:key>\n');
    request.push('						<c:value i:type="a:EntityReference">\n');
    request.push('							<a:Id>fc099ce9-78b0-4273-b921-c72e010b308f</a:Id>\n');
    request.push('							<a:LogicalName>systemuser</a:LogicalName>\n');
    request.push('							<a:Name i:nil="true" />\n');
    request.push('						</c:value>\n');
    request.push('					</a:KeyValuePairOfstringanyType>\n');
    request.push('				</a:Parameters>\n');
    request.push('				<a:RequestId i:nil="true" />\n');
    request.push('				<a:RequestName>Assign</a:RequestName>\n');
    request.push('			</request>\n');
    request.push('		</Execute>\n');
    request.push('	</s:Body>\n');
    request.push('</s:Envelope>\n');
    
    var req = new XMLHttpRequest();
    req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", true);
    
    try {
        req.responseType = 'msxml-document';
    } catch (e) {}
    req.setRequestHeader("Accept", "application/xml, text/xml, */*");
    req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
    req.onreadystatechange = function () {};
    req.send(request.join(""));


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Thursday, February 6, 2014 4:45 AM
    Moderator
  • Above solution work but I want the forms to show the changes after Assign the record which done by following Priyas solution and save the record.

    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, February 6, 2014 6:16 PM