الاثنين، 30 ديسمبر 2013

How to add System.IO.Packaging reference

add a reference to the WindowsBase Assembly.

CRM 2011:Create a Picklist That Uses a Global Option Set

// Create a picklist attribute   

                PicklistAttributeMetadata pickListAttribute = new PicklistAttributeMetadata();
                // Set base properties
                pickListAttribute.SchemaName = "new_ExampleOptionSet";
                pickListAttribute.DisplayName = new Label("Example OptionSet", 1033);
                pickListAttribute.RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None);
                //pickListAttribute.OptionSet = optionset;
                pickListAttribute.OptionSet = new OptionSetMetadata
                {
                    IsGlobal = true,
                    Name = _globalOptionSetName,
                };
                CreateAttributeRequest createAttribute = new CreateAttributeRequest();

                createAttribute.EntityName = EntityName;
                createAttribute.Attribute = pickListAttribute;
                // Execute the request.
                _Service.Execute(createAttribute);



//************************************************
http://msdn.microsoft.com/en-us/library/gg334416.aspx

الاثنين، 16 ديسمبر 2013

CRM2011:Could not find default endpoint element that references contract 'OracleService' in the ServiceModel client configuration section.

This error occur when you try run custom step workflow which call WCF service in dll file.
To solve to problem do the following:

1-Open cmd
2-run::  cd C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64
3-run: svcutil.exe WCFServiceURL /out:"C:\ServiceOutFolder\ServiceName.cs" /config:""C:\ServiceOutFolder\ServiceName.config"
4- Copy the "ServiceName.cs" and "ServiceName.config" file to your Project code.
5- Write the following code to get Service Client:
           BasicHttpBinding myBinding = new BasicHttpBinding();
            myBinding.Name = "BindingName";    // from AppConfig File
            myBinding.Security.Mode = BasicHttpSecurityMode.None;
            myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
            myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            EndpointAddress endPointAddress = new  EndpointAddress("WCFServiceURL");

            ServiceNameClient client = new ServiceNameClient(myBinding, endPointAddress);  // for ex:OracleServiceClient

// Now use this client to call methods in Service
            MyServiceName sv = client;


Your Service URL ex: http://localhost/OracleWS/OracleService.svc?wsdl

الاثنين، 25 نوفمبر 2013

How to access localhost with a port on a Virtual PC

1.Go to the Control Panel and launch Windows Firewall.

2.Go to Advanced Settings

3.Select Inbound Rules in the left pane

4.Select New Rule in the right pane

5.In the New Inbound Rule Wizard, select Port as Rule Type, then click on Next

6.Select TCP and put 900 (and any other ports you want to open) in Specific local ports, then click on Next

7.Select Allow the connection, then click on Next

8.Select the network location where the rule should apply (select them all if you're not sure), then click on Next

9.Give a name and an optional description

CRM2011:Could not load file or assembly 'microsoft.crm.sdk' or one of its dependencies.

When you publish your website you face this error to solve:
1- Open Microsoft CRM bin Folder
      C:\Program Files\Microsoft Dynamics CRM\CRMWeb\bin
2- Copy the following dll and paste to your site bin folder
     Microsoft.Crm.Sdk.dll
     Microsoft.Crm.Sdk.Proxy.dll


السبت، 23 نوفمبر 2013

السبت، 16 نوفمبر 2013

Sharepoint:The password supplied with the username Domain\username was not correct. Verify that it was entered correctly and try again

This error occurs if there has been change of password of the account and same has not been updated in SharePoint.

To solve:
1- Log in as Administrator
2- Open Command prompt
3- Write the following
cd C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN
stsadm -o updatefarmcredentials -userlogin Domain\UserName -password newpassword

4- if get the following message "Operation completed successfully" Now reset IIS, then the problem solved and you will be able to create web application.

http://cloudytech.blogspot.com/2013/05/the-password-supplied-with-username.html

الجمعة، 25 أكتوبر 2013

Interview Question and Answers

1- what is the the difference between const and readonly in C#?
   •const fields has to be initialized while declaration only, while readonly fields can be initialized at declaration     or in the constructor.
   •const variables can declared in methods ,while readonly fields cannot be declared in methods.
   •const fields cannot be used with static modifier, while readonly fields can be used with static modifier.
2- What is Boxing in C#?
   converting a value type to the reference type.
3- what is an Assembly?what is its type?

الخميس، 26 سبتمبر 2013

The permissions granted to user 'domain\username' are insufficient for performing this operation. (rsAccessDenied)

To Solve this problem do the following:
1- Run IE as Administrator.
2- Open Reporting Service configuration Manager.
3- Click Report Manager URL and open this URLs.
4- Click Folder Setting.
5- Add New Role Assignment with Selecting all roles.
 Now this message will not appeare again.

الأربعاء، 25 سبتمبر 2013

How to call a Dialog in CRM 2011 using Javascript

1- Find the ID of Dialog by Opening the Dialog and press F11 to get the URL. In the URL we could find out the ID of the Dialog.

http://server:5555/Org/sfa/workflow/edit.aspx?id=%7b91871DE4-8D25-4E3C-8772-2FE8605A5637%7d

2- write the following script to open Dialog:
function OpenDialog()
{
var dialogId = "%7b91871DE4-8D25-4E3C-8772-2FE8605A5637%7d";
 var returnValue = showModalDialog("/" + Xrm.Page.context.getOrgUniqueName() + "/cs/dialog/rundialog.aspx?DialogId=" + dialogId + "&EntityName=lead&ObjectId=" + Xrm.Page.data.entity.getId());

//Optional:To save and close entity form as soon as the dialog is closed.
Xrm.Page.data.entity.save("saveandclose");
}

الاثنين، 23 سبتمبر 2013

SQL Server Error: The instance name must be the same as computer name

To solve this proble goto this url:
http://mscrmuk.blogspot.com/2008/10/sql-server-instance-name-must-be-same.html
.......................................................................................................................................................
****************************************************************************
To check if this is the issue, use SQL Management Studio (or Query Analyzer for SQL 2000) to execute the following query:
sp_helpserver
This will return output like the following:
Name,network_name,status,id,collation_name,connect_timeout,query_timeout
ORGNAME,ORIGNAME,rpc,rpc out,use remote collation,0,null,0,0


If the value in the name column does not match the current computer name, then you have to use the following SQL stored procedures to fix the problem. Note that sp_helpserver normally returns one record, but can return more records if you have configured linked servers. If this is the case, it is the row with id=0 that matters.


To change the information you have to first remove the incorrect record, then add the correct one, with the following queries:
sp_dropserver ‘ORIGNAME’ -- where ORIGNAME is the name returned by sp_helpserver
sp_addserver ‘CURRENTNAME’, ‘LOCAL’ – where CURRENTNAME is the current computer name
Restart you computer.

CRM 2011:Web service request SetDataSourceCredentials to Report Server http://ServerName/ReportServer failed with SoapException

This error occur when you try to open report in CRM,to solve this problem do the following:
  1. Give the NetworkService the role Owner and CRMReaderRole in MSCRM_Config Database and your Organization Database.


- Open Reporting Service Configuration Manager and add the current user to Role assignment
- Remove the execution account.





الأربعاء، 18 سبتمبر 2013

CRM 2011: Adding a view to the sitemap

1- Export the Sitemap
2- Add a SubArea to the Sitemap
<SubArea Id="new_Companies" Url="/_root/homepage.aspx?etn=account&viewid=xxxxx-xxxxx-xxxxx">
  <Titles>
    <Title LCID="1033" Title="Companies" />
    <Title LCID="1025" Title="الشركات" />
  </Titles>
</SubArea>
3- Import the new Sitemap

How to Get View Id?

To Get the ID of the view you wish to display, follow these steps:
a- Navigate the the entity you wish to view.
b- Change the view to match the view in question.
c- From the Ribbon, select Copy a Link:
Open Notepad and paste the contents of the clipboard into the document.  you will see something like this:
http://ServerName:5555/TestOrg/main.aspx?etc=1&extraqs=%3fpagemode%3diframe%26sitemappath%3dSFA%257cSFA%257cnav_accts&pagetype=entitylist&viewid=%7b2C598CB7-2E3F-DE11-8035-0050569A36D3%7d&viewtype=1039
d- Copy the text from viewid through the end of the line.
e- Combine that text with the URL shown in Add Subarea to the Sitemap section.


الجمعة، 13 سبتمبر 2013

CRM 2011:Set First Characters of String To UpperCase

function SetCapitalLetters(ControlName) { 
    Xrm.Page.getAttribute(ControlName).addOnChange(function () {
    var newVal = '';  
        var CtrVal = Xrm.Page.getAttribute(ControlName).getValue();
        var CtrValues = CtrVal.split(" ");
        for (var i = 0; i < CtrValues.length; i++) {
            if (newVal == '')
                newVal = CtrValues[i].substr(0, 1).toUpperCase() + CtrValues[i].substr(1, CtrValues[i].length).toLowerCase();
            else
                newVal += ' ' + CtrValues[i].substr(0, 1).toUpperCase() + CtrValues[i].substr(1, CtrValues[i].length).toLowerCase();
        }
        SetValueAttribute(ControlName,newVal);
    });
}

الأحد، 8 سبتمبر 2013

CRM 2011: Access Is Denied (you don't have enough privileges to access Microsoft Dynamics CRM object or perform request....)

SecLib::AccessCheckEx failed. Returned hr = -2147187962, ObjectID: xxxxxxxxxxxx, OwnerId: xxxxxx,  OwnerIdType: 8 and CallingUser: xxxxxxx. ObjectTypeCode: 8, objectBusinessUnitId: xxxxxxxxxx, AccessRights: AppendToAccess Detail:
1- write the following command to SQL server
  Select Name,LogicalName From MetadataSchema.Entity Where ObjectTypeCode=8

2- Go to CRM Security role and select the user role and from the Business Management Tab give the "append" and "append to" for entity user to oirganization.

الثلاثاء، 27 أغسطس 2013

CRM 2011: Handling Tab click event

///************* Handing All From Tabs click event *****************

function TabsClickeHandler(MyFunctionName) {
            var TabLinksContainer = document.getElementById("ulTabLinks");
            var Li_items = TabLinksContainer.getElementsByTagName("li");
            for (var i = 0; i < Li_items.length; ++i) {
                //Get 'a' Tages Name.
                var Links = Li_items[i].getElementsByTagName("a");

                if (Links[0].addEventListener) {   // all browsers except IE before version 9
                    //Attach ‘onclick’ event handler to "Tab"
                    Links[0].addEventListener("click", function () { MyFunctionName(); }, false);
                }
                else if (Link[0].attachEvent) {    // IE before version 9
                    //Attach ‘onclick’ event handler to "Tab"
                    Links[0].attachEvent('onclick', function () { MyFunctionName(); });
                }
            }
        }
///**************** Handing  Only One Tab click event ********

function OneTabClickeHandler(TabId,MyFunctionName) {
            //the ID of ‘tab’
            var Tab = document.getElementById(TabId);

                if (Tab.addEventListener) {   // all browsers except IE before version 9
                    //Attach ‘onclick’ event handler to "Tab"
                    Tab.addEventListener("click", function () { MyFunctionName(); }, false);
                }
                else if (Tab.attachEvent) {    // IE before version 9
                    //Attach ‘onclick’ event handler to "Tab"
                    Tab.attachEvent('onclick', function () { MyFunctionName(); });
                }
        }

الثلاثاء، 20 أغسطس 2013

SSRS: Cannot create a connection to data source ‘CRM.’ (rsErrorOpeningConnection) Guid should contain 32 digits with 4 dashes


To run the report from the report server Url, you might find that if you are using normal domain account for username/password you will get the following error:


An error has occurred during report processing (rsProcessingAborted) Cannot create a connection to data source ‘CRM.’ (rsErrorOpeningConnection) Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

This is because the Username should be 'systemuserid' and the Password should be 'organizationid'. You can get this by running the query against the CRM database:


SELECT fullname, systemuserid, organizationid FROM FilteredSystemUser Order By fullname

الأحد، 18 أغسطس 2013

How to Select from stored procedure in SQL?

We can't execute a Stored Procedure in a Select statement.You can use a User-defined function or a view instead of a procedure

 but you can copy output from Stored Procedure to temporary table as blow:

CREATE TABLE #Result
(
  Column_Name1 Nvarchar(50),  
  Column_Name2 Int
)
INSERT #Result exec Stored_Procedure_Name @Parameter1,@Parameter2
SELECT Sum(Column_Name2) as Total  FROM #Result
where "Condition Here"
DROP TABLE #Result

الأحد، 7 يوليو 2013

Unable to Change Domain Logon Name error in CRM 2011.

1- Change “AutoGroupManagementoff” value set to 1 (false) in your registry (HKEY_LOCAL_MACHINE \SOFTWARE \Microsoft \MSCRM).
2- be sure that CRMAppPool is identified as "Network Service"

السبت، 6 يوليو 2013

Report render failure. Error: An error has occurred during report processing. (rsProcessingAborted)

setspn -L ADGROUP\dynamicsadmin

setspn -L ADGROUP\CRMSandbox

setspn -A http/WIN2K8-SQL2K8 ADGROUP\dynamicsadmin

setspn -A http/WIN2K8-SQL2K8.fqdn.com ADGROUP\dynamicsadmin

-- Also if the error contains the below details.

"System.ServiceModel.EndpointNotFoundException: Could not connect to net.tcp://ed-crmweb01/CrmSandboxSdkListener-w3wp. The connection attempt lasted for a time span of 00:00:21.0468750. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.29.3.4:808. "

Then try adding an inbound rule to the Windows firewall allowing TCP traffic on port 808, domain network. 


Also you will find a full solutions on the following link:
http://blog.cobalt.net/blog/4-steps-that-will-help-you-conquer-the-rsprocessingaborted-error

The report server cannot decrypt the symmetric key used to access sensitive

1-Open Reporting Services Configuration Manager

2-Connect to your RS server

3-Select 'Encryption Keys' from the left pane

4-Press the 'Delete' button to get rid of your encrypted content 

5-After doing this, you will need to re-set the connection strings and stored credentials on your reports.

Useful Websites

الخميس، 4 يوليو 2013

Refresh Subgrid in MS CRM 2011

function SubGridRefresh() {
    var grid = document.getElementById("subgrid1");
    if (!grid) {
        setTimeout("SubGridRefresh();", 1000);
        return;
    }
    else {
        grid.control.add_onRefresh(AlertFun);
    }
}

function AlertFun() {
    alert('SubGrid has been Refreshed');
}

السبت، 22 يونيو 2013

CRM 2011: The specified user is either disabled or is not a member of any business unit

Check whether the system administrator account was disabled in database. If yes, enable it in database.
  1. Backup the orgname_MSCRM and MSCRM_Config.
  2. Find the systemuserid for system admin in systemuserbase table.
  3. Find the system admin in systemuserbase and resourcebase, if isdisabled=True, set isdisabled=Flase.
  4. Find the Business Unit the user belongs to in businessunitbase table. if isdisabled=True, set isdisabled=Flase. 

then Restart machine.

الثلاثاء، 11 يونيو 2013

CRM 2011:Business Management error the user id associated with the current record is not valid

To Solve this error:
1- Create new user in AD (Test User)
2- From CRM Setting=>Administration=>Users Replace the user login with the new test user login.

3- Save and Login to CRM with that user.
4- Again replace new test user login with old user login (Reverse).then the problem will solve.

السبت، 8 يونيو 2013

How to Repeat Table(Tablix) Header on each Page in SSRS 2008

 To Repeat Table(Tablix) Header on each Page in SSRS 2008 do the following:
1- Click the first cell in table header.




2- From the Row Group click Static and go to properties.


















3- From properties window set the (KeepWithGroup=After) and (RepeatOnNewPage=true).

الأربعاء، 5 يونيو 2013

Page Life Cycle with an Example - ASP.Net

How to Export Gridview to Excel.












Wrtie  the following Code in Export button:

protected void btnexport_Click(object sender, EventArgs e)
    {
        try
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=gridviewdata.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sWriter = new StringWriter();
            HtmlTextWriter hWriter = new HtmlTextWriter(sWriter);
            GridView1.RenderControl(hWriter);
            Response.Output.Write(sWriter.ToString());
            Response.Flush();
            Response.End();
        }
        catch (Exception ex)
        {
            Label1.Text = ex.ToString();
        }
    }

//***********
public override void VerifyRenderingInServerForm(Control control)
 {
  }

الثلاثاء، 14 مايو 2013

CRM 2011: Javascript Xrm.Page Basics

//***** Get the value from a CRM field

 var varMyValue = Xrm.Page.getAttribute(“CRMFieldSchemaName”).getValue() ;

//****** Set the value of a CRM field

 Xrm.Page.getAttribute(“po_CRMFieldSchemaName”).setValue(‘My New Value’);

//***** Hide/Show a tab/section

 Xrm.Page.ui.tabs.get("Tab Name").setVisible(false);

 Xrm.Page.ui.tabs.get("Tab Name").sections.get("Section Name").setVisible(true);

//*****Call the onchange event of a field

 Xrm.Page.getAttribute(“CRMFieldSchemaName”).fireOnChange();

//****Get the selected value of picklist

 Xrm.Page.getAttribute(“CRMFieldSchemaName”).getSelectedOption().text;

//******Set the requirement level

 Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“none”);
 Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“required”);
 Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“recommended”);

//********Set the focus to a field

 Xrm.Page.getControl(“CRMFieldSchemaName”).setFocus(true);

//***********Stop an on save event
 event.returnValue = false;

//**** Return array of strings of users security role GUIDs:

 Xrm.Page.context.getUserRoles()


Method returns a Boolean value that indicates if any fields in the form have been modified.

Xrm.Page.data.entity.getIsDirty() 

CRM 2011 : Value cannot be null. Parameter name: localContext

This error appear when was a problem in custom plugins so that unregister this plugin.

الأربعاء، 1 مايو 2013

Send Email Attachment Using Stream

we need to send email with attachment and we didn't need to save this file to computer first and take the path 
of file in function of send email.
to solve this issue:
1-  


public void SendHtmlMail(string To, string Subject, string Body, string AttachFile, byte[] FileStream)
    {
        string SMTPServe = "smtp.gmail.com";
        string From = "email@gmail.com";
        string fromPassword = "password";
        int Port = "587";
        // smtp settings
        MailMessage message = new MailMessage(From, To, Subject, Body);

        message.IsBodyHtml = true;

        Stream ContentStream = new MemoryStream(FileStream);
        if (!string.IsNullOrEmpty(AttachFile))
        {
            System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(ContentStream, Path.GetFileName(AttachFile));
            message.Attachments.Add(attachment);
        }

        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = SMTPServe;
            smtp.Port = Port;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(From, fromPassword);
            smtp.Timeout = 80000;
        }
        try
        {
            smtp.Send(message);
            //return "Your Email has been sent";
        }
        catch(Exception ex)
        {
            throw new Exception(ex.Message);
            //return ex.Message;
        }
    }
}

2-

public static byte[] ConvertStreamToByte(Stream input)
    {
        byte[] buffer = new byte[input.Length];
        //byte[] buffer = new byte[16 * 1024];
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, read);
            }
            return ms.ToArray();
        }
    }

3-

byte[] byteArr = ConvertStreamToByte(FileUpload1.PostedFile.InputStream);
SendHtmlMail(ToEmail, Subject, Body, FileUpload1.FileName, byteArr);


السبت، 27 أبريل 2013

CRM 2011 Error:Login failed for user 'domain\Userlogin'.


Add the Microsoft Dynamics CRM server to the SQLAccessGroup group in Active Directory. To do this, follow these steps:
  1. Click the organizational unit in which you install Microsoft Dynamics CRM.
  2. Double-click SQLAccessGroup.
  3. In the SQLAccessGroup dialog box, click Members, click Add, click Object Types, click to select the Computers check box, and then click OK.
  4. In the Enter the object names to select box, type the name of the Microsoft Dynamics CRM server, and then click Check Names.
  5. Verify that the name of the Microsoft Dynamics CRM server in the Enter the object names to select box is available, and then click OK two times.
  6. Restart the Microsoft Dynamics CRM server.

الثلاثاء، 19 مارس 2013

Could not load type System.ServiceModel.Activation.HttpModule


  • This error can occur when IIS is installed after installing .NET Framework 4, or if the 3.0 version of the WCF Http Activation module is installed after installing IIS and .NET Framework 4.
    To resolve this problem, you must use the ASP.NET IIS Registration Tool (Aspnet_regiis.exe,) to register the correct version of ASP.NET. This can be accomplished by using the –iru parameters when running aspnet_regiis.exe as follows:

    1- Open Visual studio command prompt.
    2- write this command aspnet_regiis.exe -iru

السبت، 9 فبراير 2013

CRM 2011:The import file is too large to upload.

The error indicates that the file size was above the default max import file size of 8 MB. In order to change 
the default setting please apply the following steps.

Step 1:-

1.Click Start, click Run, type regedit, and then click OK.
2.Locate the following registry subkey:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ MSCRM

3.Right-click MSCRM, point to New, and then click DWORD Value to create a new DWORD value.
4.Rename the DWORD value to the following value:
OLEDBTimeout

5.Right-click the DWORD value, and then click Modify.
6.In the Edit DWORD Value dialog box, type 86400 in the Value data box, click Decimal in the Base option, and then click OK. 

7.Right-click MSCRM, point to New, and then click DWORD Value to create a new DWORD value.
8.Rename the DWORD value to the following value:
ExtendedTimeout

9.Right-click the DWORD value, and then click Modify.
10.In the Edit DWORD Value dialog box, type 1000000 in the Value data box, and then click OK. 

--------------------------------------------------
a- Open Web.Config file for CRM web Application
  1. locate the following line.

    <httpRuntime executionTimeout="300" maxRequestLength="8192"/>
    Change executionTimeout="3600" and change maxRequestLength="20000".
    then locate the following line.
    1. <httpRuntime maxRequestLength="8192"/>
    Change maxRequestLength="20000".
    Save and then close the Web.config file.

Step 2:-    

Verify the current value for the "Max" file size for data upload. By default the value is set to "8".

Use MSCRM_CONFIG
select ColumnName, IntColumn from ServerSettingsProperties
where ColumnName = 'ImportMaxAllowedFileSizeInMB'
Go 

change the default value from 8 to 12.

Use MSCRM_CONFIG
UPDATE [MSCRM_CONFIG].[dbo].[ServerSettingsProperties]
SET [IntColumn] = '12'
WHERE ColumnName = 'ImportMaxAllowedFileSizeInMB'
Go

الاثنين، 14 يناير 2013

How To Solve this Problem:a potentially dangerous request.form value was detected from the client...

1- added the following to the existing "page" directive in that .aspx file.
ValidateRequest="false"
2-add requestValidationMode="2.0" to the httpRuntime configuration section of the web.config file like the following:
 <httpRuntime requestValidationMode="2.0"/> 

الثلاثاء، 8 يناير 2013

How To Get Lookup ID,Name and EntityType in CRM 2011

First Write a function to get lookup
    function GetLookup(FieldName) {
    var lookup = Xrm.Page.data.entity.attributes.get(FieldName)
    if (lookup == null) { return null; };
    var lookupObj = lookup.getValue();
    return lookupObj[0];     
 }

1- To Get Lookup Id.
    function GetLookupId(fieldName) {
    var lookup = GetLookup(fieldName);
    if (lookup != null) {
        return lookup.id;
      }
    return null;
  }

2- To Get Lookup Name.
 function GetLookupName(fieldName) {
    var lookup = GetLookup(fieldName);
    if (lookup != null) {
        return lookup.name;
      }
    return null;
  }

3- To Get Lookup Entity Type. 
    function GetLookupEntityType(fieldName) {
    var lookup = GetLookup(fieldName);
    if (lookup != null) {
        return lookup.entityType;
      }
    return null;
  }