Understanding LookUp In CRM

Hi find out this nice post about LookUp by JimWang.

http://jianwang.blogspot.com/2008/05/mysterious-crm-lookup-i.html

Do Check it ..

Bye..

Error 0x80041110 QueryByAttribute must specify a non-empty attribute array in CRM

This error occurs when using the QueryByAttribute class we are not setting the Attributes and Values Property.

 

Just like the below code

 

Say we want to have the names of all the accounts,

 

ColumnSet myCols=new ColumnSet();

            myCols.Attributes=new string[] {“name”};

   QueryByAttribute myQA = new QueryByAttribute();

            myQA.EntityName = EntityName.account.ToString();

            myQA.ColumnSet = myCols ;           

            BusinessEntityCollection myBCColl2= myService.RetrieveMultiple(myQA);

 

However we will get error in this case because we haven’t specified Attributes and Values property. So we need to specify those properties.

 

            myQA.Attributes = new String[] { “statuscode” };

            myQA.Values=new object[] {“1”};

 

Otherwise we could use QueryByExpression class for that

 

            ColumnSet myCols=new ColumnSet();

            myCols.Attributes=new string[] {“name”};

 

            QueryExpression myQE = new QueryExpression();

            myQE.EntityName = EntityName.account.ToString();

            myQE.ColumnSet = myCols;

 

            BusinessEntityCollection myBCColl1 = myService.RetrieveMultiple(myQE);

 

 

Bye ..

Logging off from Oracle\Siebel CRM On Demand Web Service within a .NET application

There are two ways of logging off from an active session within CRM On Demand

 

// pass the url in that case no need to set the header

// only set sessionid           

string logoffUrlString = “servername/Services/Integration;jsessionid=” + SessionID + “?command=logoff”;

HttpWebRequest req = HttpWebRequest)WebRequest.Create(logoffUrlString);         

// make the HTTP call

HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); 

 

Or else

 

string logoffUrlString = “servername/Services/Integration?command=logoff”;

HttpWebRequest req = HttpWebRequest)WebRequest.Create(logoffUrlString);         

// set the session id in header

req.Headers[“JSESSIONID”] = SessionID;

// make the HTTP call

HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); 

 

Within Web Services Utilization List of Admin Tab in the CRM On Demand application we can see the login and logout info.

 

That’s it ..

Updating account record using Oracle\Siebel CRM On Demand Web Service in .NET

 

To update the Account record we need to first add web reference to the account.wsdl.

 

Than can make use of AccountUpdate method of Account Entity.

 

  // Login to the CRM server

            string loginUrlString = https://servername/Services/Integration?command=login”;

            // Get the valid Session id to be appended for each subsequent request

            String sessionID = ManageSession.Login(loginUrlString, @”orgname/username”, “password”);

            try

            {

                // Download the account wsdl from the Admin section of the CRM application

                // Add web reference to the wsdl

                // Create the instance of the opportunity entity

                Account myAcc = new Account();

                myAcc.Url = https://secure-ausomxapa.crmondemand.com/Services/Integration;jsessionid=” + sessionID;               

                // Create the instance of Account Data

                AccountData[] myAccData = new AccountData[1];

                myAccData[0] = new AccountData();

                // the order number to be updated

                myAccData[0].stOrder_Number = “orderNumber”;

                // the id of the account to be updated

                myAccData[0].Id = “orderID”;

                // creating ListOfAccountData object

                ListOfAccountData myLstOfAcctData = new ListOfAccountData();

                myLstOfAcctData.Account = myAccData;

                // using AccountUpdate_Input

                AccountUpdate_Input myAccUpdateInput = new AccountUpdate_Input();

                myAccUpdateInput.ListOfAccount = myLstOfAcctData;

                // using account’s Accout Update method to update the record               

                AccountUpdate_Output myAccntUpdateOutput = myAcc.AccountUpdate(myAccUpdateInput);

            }

            catch (SoapException ex)

            {

            }

            catch (Exception ex)

            {

            }

 

 

That’s it …

Using Oracle CRM On Demand Web Service to query Opportunity Data in .NET

1) Create a windows application

2) Put the following code in the form load event handler

 

Explaination is put in as comment

 

 

private void Form1_Load(object sender, EventArgs e)

        {         

            // Login to the CRM server

            string loginUrlString = https://servername/Services/Integration?command=login”;          

            // Get the valid Session id to be appended for each subsequent request

            String sessionID = ManageSession.Login(loginUrlString, @”orgname/username”, “pwd”);

 

            try

            {

                // Download the opportunity wsdl from the Admin section of the CRM application

                // Add web reference to the wsdl

                // Create the instance of the opportunity entity

                Opportunity myOpp = new Opportunity();

                myOpp.Url = https://servername/Services/Integration;jsessionid=” + sessionID;

                // Set the query

                // To find the record with sales stage as closed/won

                queryType mySalesStage = new queryType();

                mySalesStage.Value = “LIKE ‘Closed/Won'”;

                // Values needed back from the server

                // 1) Purchase Order Date

                queryType myPODate = new queryType();

                myPODate.Value  = “”;

                // 2) Purchase Order Number

                queryType myPONumber = new queryType();

                myPONumber.Value  = “”;

                // 2) Opportunity Name

                queryType myOppName=new queryType();

                myOppName.Value=“”;   

               

                // Create opportunityquery instance and set the appropriate parameters

                OpportunityQuery myOppQuery = new OpportunityQuery();

                myOppQuery.SalesStage = mySalesStage;

                myOppQuery.dtPurchase_Order_Date = myPODate;

                myOppQuery.stPurchase_Order_No = myPONumber;

                myOppQuery.OpportunityName = myOppName;

 

                // Set ListOfOpportunityQuery

                ListOfOpportunityQuery lstOfOppQuery = new ListOfOpportunityQuery();

                lstOfOppQuery.Opportunity = myOppQuery;

                // Number of records to fetch

                lstOfOppQuery.pagesize = “100”;

 

                // set OpportunityQueryPage_Input

                OpportunityQueryPage_Input myOppInput = new OpportunityQueryPage_Input();

                myOppInput.ListOfOpportunity = lstOfOppQuery;

               

                // Get the output

                OpportunityQueryPage_Output myOutput = myOpp.OpportunityQueryPage(myOppInput);

 

                // Get ListOfOpportunityData

                ListOfOpportunityData myOppData = myOutput.ListOfOpportunity;

                OpportunityData[] oppData = myOppData.Opportunity;

                // Total number of records returned

                MessageBox.Show(oppData.GetLength(0).ToString());

 

                foreach(OpportunityData oData in oppData)

                {

                    MessageBox.Show(“Opportunity Name :-“ + oData.OpportunityName

                        + “, Opp PO Date =” + oData.dtPurchase_Order_Date.ToShortDateString()

                        + ” Opp PO Number =” + oData.stPurchase_Order_No);                 

 

                }

   }

            catch (SoapException ex)

            {

                MessageBox.Show(ex.Detail.InnerXml);

            }

 

 

The code for ManageSession.Login static mehtod

 

public static String Login(String loginUrlString, String userName, String password)

        {

        try

        {

            // create a http request and set the headers for authentication

            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(loginUrlString);

            HttpWebResponse myResponse;

            myRequest.Method = “POST”;

            // passing username and password in the http header

            // username format if it includes slash should be the forward slash /

            myRequest.Headers[“UserName”] = userName;

            myRequest.Headers[“Password”] = password;          

            myResponse = (HttpWebResponse)myRequest.GetResponse();

            Stream sr = myResponse.GetResponseStream();

            // retrieve session id

            char[] sep = { ‘;’ };

            String[] headers = myResponse.Headers[“Set-Cookie”].Split(sep);

            for (int i=0; i <= headers.Length-1; i++)

            {

            if (headers[i].StartsWith(“JSESSIONID”))

            {

            sep[0] = ‘=’;

            SessionID = headers[i].Split(sep)[1];

            break;

            }

            }

            sr.Close();

            myResponse.Close();

        }

        catch (WebException webException)

        {

           

        }

        catch (Exception ex)

        {

        }

        // send back the session id that should be passed to subsequent calls

        // to webservices

        return SessionID;       

        }

 

That’s it …

Using Siebel CRM On Demand Web Services in Microsoft.NET

1) Create a new windows application.

2) Put the following code in the form load

private void Form1_Load(object sender, EventArgs e)

{

string loginUrlString = https://servername/Services/Integration?command=login&#8221;;

String sessionID = ManageSession.Login(loginUrlString, @”orgname-devusername”, “password”);

}

3) Define the login method within ManageSession class in the following manner


public static string SessionID = “”;

public static String Login(String loginUrlString, String userName, String password)

{

try

{

// create a http request and set the headers for authentication

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(loginUrlString);

HttpWebResponse myResponse;

myRequest.Method = “POST”;

// passing username and password in the http header

// username format if it includes slash should be the forward slash /

myRequest.Headers[“UserName”] = userName;

myRequest.Headers[“Password”] = password;

myResponse = (HttpWebResponse)myRequest.GetResponse();

Stream sr = myResponse.GetResponseStream();

// retrieve session id

char[] sep = { ‘;’ };

String[] headers = myResponse.Headers[“Set-Cookie”].Split(sep);

for (int i=0; i <= headers.Length-1; i++)

{

if (headers[i].StartsWith(“JSESSIONID”))

{

sep[0] = ‘=’;

SessionID = headers[i].Split(sep)[1];

break;

}

}

sr.Close();

myResponse.Close();

}

catch (WebException webException)

{

}

catch (Exception ex)

{

}

// send back the session id that should be passed to subsequent calls

// to webservices

return SessionID;

}

That’s it..

The remote server returned an error: (500) Internal Server Error while using Siebel CRM On Demand Web Services.

I got this error while trying to Logging In to the Web Services Session using .NET. Spent whole day for finding out what could be the reason behind the issue. Finally came to know the issue was because of the username being not passed correctly.

 

The username that we were passing was in this particular format that we would normally do

 

 ‘orgname-devusername’

 

Whereas it was expecting it in this format

 

‘orgname-dev/username’

 

i.e. forward slash instead of the back slash.

 

I hope it helps!