Assign record using JScript in CRM 2011
Hi,
Below is the Jscript to assign a record to particular User using SOAP.
function AssignRecord(Assignee, Target, entityName) {
var request = “<s:Envelope xmlns:s=\”http://schemas.xmlsoap.org/soap/envelope/\”>”;
request += “<s:Body>”;
request += “<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\””;
request += ” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
request += “<request i:type=\”b:AssignRequest\””;
request += ” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\””;
request += ” xmlns:b=\”http://schemas.microsoft.com/crm/2011/Contracts\”>”;
request += “<a:Parameters xmlns:c=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
request += “<a:KeyValuePairOfstringanyType>”;
request += “<c:key>Target</c:key>”;
request += “<c:value i:type=\”a:EntityReference\”>”;
request += “<a:Id>” + Target + “</a:Id>”;
request += “<a:LogicalName>” + entityName + “</a:LogicalName>”;
request += “<a:Name i:nil=\”true\” />”;
request += “</c:value>”;
request += “</a:KeyValuePairOfstringanyType>”;
request += “<a:KeyValuePairOfstringanyType>”;
request += “<c:key>Assignee</c:key>”;
request += “<c:value i:type=\”a:EntityReference\”>”;
request += “<a:Id>” + Assignee + “</a:Id>”;
request += “<a:LogicalName>systemuser</a:LogicalName>”;
request += “<a:Name i:nil=\”true\” />”;
request += “</c:value>”;
request += “</a:KeyValuePairOfstringanyType>”;
request += “</a:Parameters>”;
request += “<a:RequestId i:nil=\”true\” />”;
request += “<a:RequestName>Assign</a:RequestName>”;
request += “</request>”;
request += “</Execute>”;
request += “</s:Body>”;
request += “</s:Envelope>”;
// Get server URL
var serverUrl = Xrm.Page.context.getServerUrl();
var req = new XMLHttpRequest();
req.open(“POST”, serverUrl, true)
// Responses will return XML. It isn’t possible to return JSON.
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 () { assignResponse(req); };
req.send(request);
}
// This function gets called after the execution
function assignResponse(req) {
if (req.readyState == 4) {
if (req.status == 200) {
alert(“Success !!!”);
}
else {
alert(“Error – ” + req.responseXML);
}
}
}
How Do I Call this function :-
- Pass User Id, Record Id and Entity name to the function
var userId = “” // GUID of user whome to assign the record
var recordId = “” // GUID of record you want to assign
var entityName = “” // Entity name the record
AssignRecord(userId,recordId,entityName);
Hope it helps 🙂
Hi Rajeev ,
i am using above code to assign an QueueItem from Sourece Queue to Destination Queue with User Guid.
But the Code throwing error. have u tested this code , please share if any missed.
Thanks,
Suresh Kumar D
Hi,
There is separate request “AddToQueueRequest” to assign the QueueItem.
Have a look at
http://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.addtoqueuerequest.aspx
I get “success”, but nothing seems to happen – the record does not get assigned. Any ideas?
Hi,
Can you enable ‘Audit’ for that entity and check if any background process undo the Assign?
Hi,
Did you solve your problem? I also used the code and i received success message but nothings happened in the owner even refresh the page
I found that the GUIDs retrieved had curly brackets in the string values. Removing the {} characters before constructing the SOAP reply solved the problem.
Hi All,
I am getting below issue while calling above function:
var LoadStartTime = new Date().getTime();
function markRenderTime(){if(!document || !document.body || document.readyState !== ‘complete’){window.setTimeout(markRenderTime,0);} else {if(!window.PostRenderTime){window.PostRenderTime = (new Date()).getTime();}}}
window.setTimeout(markRenderTime, 0);
var LOCID_IPADWINCLOSED = ‘An error has occurred. Please return to the home page and try again.’;
var LOCID_SCREEN_RESOLUTION_ERROR = ‘Microsoft Dynamics CRM requires a screen resolution of at least 800 x 600. Please increase the resolution of your display.’;
var LOCID_UI_DIR = ‘LTR’;
var LOCID_ACTION_UNSUPPORTED_ERROR = ‘This action is not supported.’;
var LOCID_UNSUPPORTED_RIBBONACTION = ‘This action is not supported on the browser that you are using.’;
var LOCID_LOOKUP_LABEL_FOR_EDIT = ‘\x7b0\x7d \x7b1\x7d’;
var LOCID_FIRST_WEEK_SELECT = ‘FirstDay’;
var LOCID_BU_CANNOTDISABLE = ‘It has been detected that this operation would deactivate all remaining business units and cannot proceed.’;
var LOCID_REMOTECOMMAND_ERROR = ‘An error has occurred. Try this action again. If the problem continues, check the Microsoft Dynamics CRM Community for solutions or contact your organization\x27s Microsoft Dynamics CRM Administrator. Finally, you can contact Microsoft Support.’;
var LOCID_NON_SRS_FILTERSCHEDULE = ‘Only SQL Server Reporting Services reports can be filtered or scheduled.’;
var WEB_APP_URL = ”;
var READ_FORM_ENABLED = true;
var HELP_SKU = ‘OP’;
var IS_OUTLOOK_LAPTOP_CLIENT = false;
var IS_OUTLOOK_14_CLIENT = false;
var CLIENT_MAJOR_VERSION = 5;
var WEB_RESOURCE_ORG_VERSION_NUMBER = ‘\x7b635548526710004376\x7d’;
var _DebugOnScriptError = false;
var ORG_UNIQUE_NAME = ‘Microsoft’;
var ORG_ID = ‘\x7b5D1AEEA0-E54C-4DA1-A273-FB0D413C5BD6\x7d’;
var USE_READ_FORM = false;
var IS_PATHBASEDURLS = true;
var USER_HELP_LCID = 1033;
var USER_LANGUAGE_CODE = 1033;
var IS_OUTLOOK_CLIENT = false;
var IS_UEIP_ENABLED = false;
var IS_ONLINE = true;
var VERSION_STAMP = 1511628315;
var ISV_ADDITIONAL_AUTH = ”;
var FeatureControl = {“FCB.Refresh.Fall”:false,”FCB.Refresh.Sales”:false,”FCB.Refresh.Common”:false,”FCB.Refresh.Service”:false};
var REQ_ID = ‘8366fceb-69cc-4cc5-ae14-2e9e530b8f4c’;
var IS_LIVE = false;
var IS_ONPREMISE = true;
var IS_SPLA = false;
var IS_CLAIMS = false;
var UseTabletExperience = false;
var _ErrorCodesIsvAborted = ‘0x80040265’;
var ScriptErrorReportingPreference = 3;
var _bPresenceEnabled = false;
var ChangeDoubleQuoteToSingleQuote = false;
var ORG_LANGUAGE_CODE = 1033;
var ORG_FULLNAME_FORMAT = 1;
var ORG_IS_APP_MODE = false;
var SERVER_URL = ‘https\x3a\x2f\x2fcy1msscusdwb01.partners.extranet.microsoft.com\x2fMicrosoft’;
var AUTHENTICATION_TYPE = 0;
var CRM2007_WEBSERVICE_NS = ‘http\x3a\x2f\x2fschemas.microsoft.com\x2fcrm\x2f2007\x2fWebServices’;
var CRM2007_CORETYPES_NS = ‘http\x3a\x2f\x2fschemas.microsoft.com\x2fcrm\x2f2007\x2fCoreTypes’;
var CURRENT_THEME_TYPE = ‘Outlook14Silver’;
var CURRENT_WEB_THEME = ‘Default’;
var RefreshFormTheme = ‘Outlook15White’;
var USER_ROLES = [‘bd4922d4-b855-dd11-8926-001e0bda1a14’, ‘7788bbae-9ebe-e011-90ad-00155dc3120c’];
var USER_GUID = ‘\x7b8419F084-5384-E411-9420-002DD8210F4A\x7d’;
var ORG_DATE_START_DAY = 0;
var USER_DATE_FORMATSTRING = ‘M\x2fd\x2fyyyy’;
var USER_DATE_SEPARATOR = ‘\x2f’;
var USER_DATE_FORMATTED_FORMATSTRING = ‘M\x2fd\x2fyyyy’;
var USER_DATE_START_DAY = 0;
var USER_TIME_FORMAT = ‘h\x3amm tt’;
var USER_SHOW_WEEK_NUMBER = false;
var ORG_TIMEZONE_OFFSET = -480;
var __cultureInfo = {“dateTimeFormat”:{“AMDesignator”:”AM”,”Calendar”:{“MinSupportedDateTime”:”\/Date(-62135568000000)\/”,”MaxSupportedDateTime”:”\/Date(253402300799999)\/”,”AlgorithmType”:1,”CalendarType”:1,”Eras”:[1],”TwoDigitYearMax”:2029,”IsReadOnly”:false},”DateSeparator”:”/”,”FirstDayOfWeek”:0,”CalendarWeekRule”:0,”FullDateTimePattern”:”dddd, MMMM d, yyyy h:mm:ss tt”,”LongDatePattern”:”dddd, MMMM d, yyyy”,”LongTimePattern”:”h:mm:ss tt”,”MonthDayPattern”:”MMMM dd”,”PMDesignator”:”PM”,”RFC1123Pattern”:”ddd, dd MMM yyyy HH\u0027:\u0027mm\u0027:\u0027ss \u0027GMT\u0027″,”ShortDatePattern”:”M/d/yyyy”,”ShortTimePattern”:”h:mm tt”,”SortableDateTimePattern”:”yyyy\u0027-\u0027MM\u0027-\u0027dd\u0027T\u0027HH\u0027:\u0027mm\u0027:\u0027ss”,”TimeSeparator”:”:”,”UniversalSortableDateTimePattern”:”yyyy\u0027-\u0027MM\u0027-\u0027dd HH\u0027:\u0027mm\u0027:\u0027ss\u0027Z\u0027″,”YearMonthPattern”:”MMMM yyyy”,”AbbreviatedDayNames”:[“Sun”,”Mon”,”Tue”,”Wed”,”Thu”,”Fri”,”Sat”],”ShortestDayNames”:[“Su”,”Mo”,”Tu”,”We”,”Th”,”Fr”,”Sa”],”DayNames”:[“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”],”AbbreviatedMonthNames”:[“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”,””],”MonthNames”:[“January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”,””],”IsReadOnly”:false,”NativeCalendarName”:”Gregorian Calendar”,”AbbreviatedMonthGenitiveNames”:[“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”,””],”MonthGenitiveNames”:[“January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”,””]},”eras”:[1,”A.D.”,null,0],”name”:”en-US”,”numberFormat”:{“CurrencyDecimalDigits”:2,”CurrencyDecimalSeparator”:”.”,”IsReadOnly”:false,”CurrencyGroupSizes”:[3],”NumberGroupSizes”:[3],”PercentGroupSizes”:[3],”CurrencyGroupSeparator”:”,”,”CurrencySymbol”:”$”,”NaNSymbol”:”NaN”,”CurrencyNegativePattern”:0,”NumberNegativePattern”:1,”PercentPositivePattern”:0,”PercentNegativePattern”:0,”NegativeInfinitySymbol”:”-Infinity”,”NegativeSign”:”-“,”NumberDecimalDigits”:2,”NumberDecimalSeparator”:”.”,”NumberGroupSeparator”:”,”,”CurrencyPositivePattern”:0,”PositiveInfinitySymbol”:”Infinity”,”PositiveSign”:”+”,”PercentDecimalDigits”:2,”PercentDecimalSeparator”:”.”,”PercentGroupSeparator”:”,”,”PercentSymbol”:”%”,”PerMilleSymbol”:”‰”,”NativeDigits”:[“0″,”1″,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9″],”DigitSubstitution”:1}};
var HELP_SERVER_URL = ‘https\x3a\x2f\x2fconnectus.partners.extranet.microsoft.com\x2f’;
var HELP_REDIRECT_AVAILABLE = false;
var WEB_SERVER_HOST = ‘cy1msscusdwb01.partners.extranet.microsoft.com’;
var WEB_SERVER_PORT = 443;
var APPLICATION_VERSION = ‘5.0’;
var APPLICATION_FULL_VERSION = ‘5.0.9690.4376’;
var IMAGE_STRIPS_ENABLED = true;
var DEF_SOL_ID = ‘\x7bfd140aaf-4df4-11dd-bd17-0019b9312238\x7d’;
var YAMMER_IS_INSTALLED = false;
var YAMMER_IS_CONFIGURED_FOR_ORG = false;
var YAMMER_APP_ID = ”;
var YAMMER_NETWORK_NAME = ”;
var YAMMER_GROUP_ID = 0;
var YAMMER_TOKEN_EXPIRED = false;
var YAMMER_IS_CONFIGURED_FOR_USER = false;
var YAMMER_HAS_CONFIGURE_PRIVILEGE = false;
var YAMMER_POST_METHOD = 0;
var MARKERS_CACHE_ID = ‘8366fceb-69cc-4cc5-ae14-2e9e530b8f4c’;
var _sWebServicesNamespace = ‘http\x3a\x2f\x2fschemas.microsoft.com\x2fcrm\x2f2009\x2fWebServices’;
var ERRORCODE_ETM = ‘0x8004A001’;
var EDIT_PRELOAD = true;
var _aWrpcTokens = {};
var initialFormXml = ”;
var APP_SOLUTION_ID = ”;
function loadScript(sUrl, sId){ document.write(”); }
function loadAllScriptIncludes_header() {
loadScript(‘\x2fMicrosoft\x2f_common\x2fentityproperties\x2fentitypropertiesutil.js.aspx\x3ftstamp\x3d2103407176\x26amp\x3bver\x3d1511628315’, ‘\x2fMicrosoft\x2f_common\x2fentityproperties\x2fentitypropertiesutil.js.aspx\x3ftstamp\x3d2103407176\x26amp\x3bver\x3d1511628315’);
Sys.Application.add_init(function crmApplicationInitHandler() {if (!document.body || document.body.children.length === 0) return;});}
if (!!window.globalAshxLoaded) loadAllScriptIncludes_header();
function HeaderWindowOnLoad()
{
if(!window.PostRenderTime){window.PostRenderTime = (new Date()).getTime();}
_aWrpcTokens[‘\x2fMICROSOFT\x2fAPPWEBSERVICES\x2fSCRIPTERROR.ASMX’]={Token: ’54VKPInFEeSUIAAt2CEPSjG1cScNcXmHY2s7UYxBA7aC5Cgx0Wa8uRdFpVgfKS0T’, Timestamp: “635555985450570440”};
}
if(window.Sys){Sys.Application.add_load(HeaderWindowOnLoad);}else{setTimeout(HeaderWindowOnLoad, 1000);}
var _pageResourceManagerUnLoad = function(){try{window.$removeHandler(window, ‘unload’, _pageResourceManagerUnLoad);_pageResourceManagerUnLoad=null;}catch(exc){}window.onresize=null;window.onerror=null;window.onload=null;}
if(window.$addHandler){$addHandler(window, ‘unload’, _pageResourceManagerUnLoad);}
Microsoft Dynamics CRM
Important:
Microsoft Dynamics CRM makes extensive use of your Web browser’s client-side abilities, including ActiveX scripting. You either have one of these features turned off or your security settings are set so high that they prevent these features from being used. To enable these features, add the Microsoft Dynamics CRM Server URL (http://cy1msscusdwb01.partners.extranet.microsoft.com) to your list of Trusted Sites and try your request again.
To assign the Microsoft Dynamics CRM site to the Trusted sites security zone:
1. In Internet Explorer, on the Tools menu, click Internet Options.
2. Click the Security tab, and then click the Trusted sites zone.
3. Click Sites.
4. In the Add this Web site to the zone box, type http://cy1msscusdwb01.partners.extranet.microsoft.com, and then click Add.
function load()
{
var isLoaded = false;
if (window.screen.width < 768)
{
alert(LOCID_SCREEN_RESOLUTION_ERROR);
}
else
{
try
{
if (!IsNull(openStdWin(Mscrm.CrmUri.create("/main.aspx"), "MSCRM_MAIN", 0, 0, "menubar=0, location=0, resizable=1, status=1")))
{
isLoaded = true;
}
}
catch (e)
{
}
}
if ((window.name != "MSCRM_MAIN") && (isLoaded == true))
{
var oMe = window.self;
oMe.opener = window.self;
closeWindow();
}
}
function ActiveXTest()
{
if ('ActiveXObject' in window)
{
try
{
return new ActiveXObject("Microsoft.XMLDOM");
}
catch (e)
{
return false;
}
}
return true;
}
function XmlTest()
{
try
{
return oXmlHttp = new XMLHttpRequest();
}
catch (e)
{
return false;
}
}
function ScriptTest()
{
try
{
var sDate = new Date().toDateString();
return true;
}
catch (e)
{
return false;
}
}
function PageOnLoad()
{
if (ActiveXTest())
{
if (XmlTest())
{
if (ScriptTest())
{
window.location.replace('\x2fMicrosoft\x2fmain.aspx');
}
else
{
window.location.replace(Mscrm.CrmUri.create("/_common/error/unsupportedScriptVersion.aspx").toString());
}
}
else
{
window.location.replace(Mscrm.CrmUri.create("/_common/error/unsupportedXmlDom.aspx").toString());
}
}
else
{
window.location.replace(Mscrm.CrmUri.create("/_common/error/unsupportedSecurity.aspx").toString());
}
}
$addHandler(window, "load", PageOnLoad);