Pass Guid as String in XmlHTTP

I can't figure out where I'm going wrong...I am new at this and trying to get the whole concept. Any assistance would be GREATLY appreciated!

List 1 Questions

Using the code below, I am able to get this alert:

Alert oXmlHTTP.responseXML.xml:
< xml version="1.0" >
<string xmlns="http://tempuri.org/">A1 Client TEST</string>
oXmlHTTP.responseXML.xml.toString().length: 84

Then the alert:

Inside check to see if we have a valid response

Then the alert:

Service Returns parentaccount back in a string node: A1 Client TEST

(this is the name of the parent object I am trying to return - I also need the GUID returned as a string, which is where I'm lost; I know the object type code = 1 for Account)

Last alert:

999Inside Exception

Listing 2 Questions

I am able to run the parentaccount code - this brings up a website with a link for RetrieveAccount

I enter in the TEST Values of my Project object:

Id: 6415DF41-F023-DB11-BC70-001422B41910
Entity Type Code: 10000
<INVOKE> returns

< xml version="1.0" encoding="utf-8" >
<string xmlns="http://tempuri.org/">A1 Client TEST</string>

A1 Client TEST is the Account Name that I am trying to populate on the form. I also need to get is the GUID as a string.

Here is the entire code

Listing 1 onLoad.js

Alert oXmlHTTP.responseXML.xml:

< xml version="1.0" >

<string xmlns="http://tempuri.org/">A1 Client TEST</string>

oXmlHTTP.responseXML.xml.toString().length: 84

/*
Audio One Incident onLoad Event
By Marty at IES, 08/26/2006
*/

// Hide label from form ... Warning: hiding may be unsupported by Microsoft
// crmForm.all.ies_flag.style.display = 'none';
// crmForm.all.ies_flagqueueassigned.style.display = 'none';

var url = "http://audiocrm:5555/workingwithcrm/parentaccount.asmx/RetrieveAccount";

// gather field values
var oFlag = crmForm.all.ies_flag;
var oFlagQueueAssigned = crmForm.all.ies_flagqueueassigned;
var oAccount = crmForm.all.customerid;
var oProject = crmForm.all.ies_projectid;
var oRoom = crmForm.all.ies_roomid;
var oPOStage = crmForm.all.ies_postage;
var oProductDueDate = crmForm.all.ies_productduedate;
var oTab3 = crmForm.all.tab3Tab;
var ticketnumber = crmForm.all.ticketnumber;
var oGuid = crmForm.ObjectId;
var oRequiresApproval = crmForm.all.ies_requiresapproval;
var oApprovalStatus = crmForm.all.ies_approvalstatus;

// alert("OnLoad Begins\noFlag.DataValue: "+oFlag.DataValue+"\noFlagQueueAssigned.DataValue: "+oFlagQueueAssigned.DataValue+"\noPOStage.DataValue: "+oPOStage.DataValue);
// if New Case
// alert("Verify New, Not Existing Case: oGuid == null: "+(oGuid == null)+"\noFlagQueueAssigned.DataValue: "+oFlagQueueAssigned.DataValue+"\noPOStage.DataValue: "+oPOStage.DataValue);

if (oGuid == null)
{
// alert("New Case");
// oFlag.DataValue = 0;
// oFlagQueueAssigned.DataValue = 0;
// Project Entity created case
// alert("Project Entity Created Case");
if (oProject.DataValue != null)
{
// The lookup field contains an array of values
var aProject = new Array();
aProject = oProject.DataValue;
// Get the values from the first record
var sId = aProject[0].id;
var sObjectTypeCode = aProject[0].type;
// Remove the braces from the GUID
sId = sId.replace(/[{,}]/g, "");
alert("1Project: "+oProject+"\naProject: "+aProject+"\nsId: "+sId+"\nsObjectTypeCode: "+sObjectTypeCode);
}
alert("2Project: "+oProject+"\naProject: "+aProject+"\nsId: "+sId+"\nsObjectTypeCode: "+sObjectTypeCode);
// Leave the Account Name blank if there are any errors from our service call
try
{
// Use XMLHTTP connection to Web server containing SDK code to retrieve the Account Name
// var oXmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
var oXmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
alert("oXmlHTTP: "+oXmlHTTP);

// Open connection to Web service
oXmlHTTP.Open("POST", url, false);

// Set a header to tell the browser we are sending posted data
oXmlHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")

// Send request, passing in the GUID and object type code
oXmlHTTP.Send("id=" + sId + "&EntityTypeCode=" + sObjectTypeCode);

// Parse the response to the parentaccount variable
var parentaccount = "";
alert("oXmlHTTP.responseXML.xml: \n"+oXmlHTTP.responseXML.xml+"\noXmlHTTP.responseXML.xml.toString().length: "+oXmlHTTP.responseXML.xml.toString().length);

// Check to see if we have a valid response
if ((oXmlHTTP.responseXML.xml) != null && (oXmlHTTP.responseXML.xml.toString().length > 0))
{
alert("Inside Check to see if we have a valid response");
// The service will return the Account Name back in a string node
parentaccount = oXmlHTTP.responseXML.selectSingleNode("string").text;
alert("Service Returns parentaccount back in a string node: "+parentaccount);
}

// Assign response back to Account Name field
oAccount.DataValue = parentaccount;
oAccount.id = Guid;
oAccount.type = 1;
oAccount.name = parentaccount;

alert("Account Name : "+oAccount.DataValue+"\nGuid: "+Guid);
}
catch(e)
{
alert("999Inside Exception ");
}
}

Listing 2 - parentaccount.asmx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

using WorkingWithCrm.CrmSdk;

namespace WorkingWithCrm
{
public class parentaccount : System.Web.Services.WebService
{
public parentaccount () {}

[WebMethod]
// public string RetrieveAccount(string Id, int EntityTypeCode)
public string RetrieveAccount(string Id, Guid AccountId)

{
// Standard CRM service setup
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.Url = "http://audiocrm:5555/mscrmservices/2006/crmservice.asmx";

// Create the Column Set object indicating the fields to be retrieved
ColumnSet cols = new ColumnSet();
cols.Attributes = new string [] {parentcustomerid");
account
string ret = string.Empty;

// Ensure that we have a string that can be converted to a GUID
if (ValidGuid(Id))
{
// oGuid is the GUID of the record being retrieved
Guid oGuid = new Guid(Id);

try
{
// The EntityName indicates the EntityType of the object being retrieved
// cols.Attributes = new string[] { "customerid" };
cols.Attributes = new string[] { "ies_accountid" };
ies_project ies_project = (ies_project)service.Retrieve(EntityName.ies_project.ToString(), oGuid, cols);
ret = ies_project.ies_accountid.name;
}
catch(System.Web.Services.Protocols.SoapException ex)
{
ret = "Error: " + ex.Detail.InnerXml;
}
}
else
{
ret = "no Account Object";
}

return ret;
}

/// <summary>
/// Determines whether the given string is a valid GUID (enclosed brackets are optional).
/// </summary>
/// <remarks>
/// This method will return true if the string is in a 8-4-4-4-12 format, optionally
/// enclosed in brackets; otherwise it will return false.
/// </remarks>
/// <param name="guid"></param>
/// <returns></returns>
public static bool ValidGuid(string Guid)
{
return ((System.Text.RegularExpressions.Regex) new System.Text.RegularExpressions.Regex(@"^\{ [a-fA-F\d]{8}-([a-fA-F\d]{4}-){3}[a-fA-F\d]{12}\} $", System.Text.RegularExpressions.RegexOptions.Singleline | System.Text.RegularExpressions.RegexOptions.Compiled)).IsMatch(Guid);
}
}
}




Answer this question

Pass Guid as String in XmlHTTP

  • Abhishek bhadouria

    You question does not appear to be related to Windows Workflow Foundation and am not sure which forum is the right one for you to ask your question. You can start with the Where Is the Forum For... forum.



  • Pass Guid as String in XmlHTTP