function GetBusinessUnit() {
var request = "<request i:type='b:WhoAmIRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts' xmlns:b='http://schemas.microsoft.com/crm/2011/Contracts'>" +
"<a:Parameters xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic' />" +
"<a:RequestId i:nil='true' />" +
"<a:RequestName>WhoAmI</a:RequestName>" +
"</request>";
var resultXml = XrmServiceToolkit.Soap.Execute(request);
var buid = resultXml.getElementsByTagName("a:Results")[0].childNodes[1].childNodes[1].text;
var cols = ["name"];
var retrievedContact = XrmServiceToolkit.Soap.Retrieve("businessunit", buid, cols);
var businessUnitName = retrievedContact.attributes['name'].value;
alert(businessUnitName);
}
After that you need to add the following files to the Form Libraries.
- Jquery
- Json2
- XrmServiceToolkit
Download these files from the following link: XrmServiceToolkit
Hi Kanagaraj, I received "microsoft jscript runtime error: undefined", Please let me know the solution
ReplyDeleteThe above error is in CRM which is IFD. since it is IFD, the url is different when compared to its original URL.
ReplyDeleteI facing problem on this, please let me know the solution for this.
Did you try to debug your code and checked in which line you are getting this error?
Deleteyes, error was in the below line,
Deletevar resultXml = XrmServiceToolkit.Soap.Execute(request);
But, It is working fine in my another CRM.
Problem is as i told it is an IFD CRM
Maybe it is a bug of XrmServiceToolkit,you can solved it by call getClientUrl instead of getServiceUrl,here(http://xrmservicetoolkit.codeplex.com/discussions/438589)is the link discuss about this
DeleteI'm getting this error....
ReplyDeleteField:window
Event:onload
Error:The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/crm/2011/Contracts/Services:id. The InnerException message was 'There was an error deserializeing the object of type System.Guid. The value '' cannot be parsed as the type 'Guid'.'. Please see InnerException for more details.
Huh?
Just traced the error.
ReplyDeleteHere is the fix:
var buid = resultXml.getElementsByTagName("a:Results")[0].childNodes[1].childNodes[1].textContent;
Hi,
ReplyDeleteit worked for me
thanks
Easy way
ReplyDeletefunction GetUserBS()
{
var ContactID = Xrm.Page.context.getUserId();
Cols = ["businessunitid"];
var Retrieved = XrmServiceToolkit.Soap.Retrieve ("systemuser", ContactID, Cols );
var UnitObj = Retrieved.attributes["businessunitid"];
var UnitName = UnitObj.name
return (UnitName);
}