How to highlight code in hosted wordpress blogs

This has been something that has been annoying me for quite a while, how do I show c# and javascript code in the blog in a decent way.

The other important factor to note here is I am using a hosted blog, so all the solutions with plugins are no good to me.

Well I finally figured it out thanks to this stackoverflow page here

you put this in your code but make sure you put it in the Visual view and not the HTML. I’m not sure how to type this so I have typed the square bracket rather than putting them in (because then it puts in code)

 

[sourcecode language='javascript']
[/sourcecode]

here is an example


function customerid_onchange(){
 // Get value of the selected customer account
 var lookupItem = Xrm.Page.getAttribute("parentcustomerid").getValue();

CRM2011 OptionSetId Cannot be Changed when Importing Unmanaged Solution

I had an unusual problem today, I say unusual I mean irritating.

I had a solution which was unmanaged and I had imported it to an organisation.

I then worked on my solution further and at some point I decided some of the Option Sets should change from entity level to global option sets.

When I then exported my solution and tried to import it into the organisation which had an early version.

It failed, it gave the error

OptionSetId cannot be changed when importing

The only useful part of the error message was it told me it was an option set, it didn’t tell me which one.

It took me a while to work out which option set was causing me problems but in the end I removed and deleted most of them until I got the right one.

This forum post was quite useful for pointing me in the right direction.

It certainly is a good argument to use managed solutions rather than unmanaged, the ability to remove the solution before importing sounds very useful (not to mention the customer not being able to change anything).

I thought I would write a blog post about this because when I googled the problem, hardly anything came up.

CRM 2011 – Javascript code to lookup parent customer addresses from contact form

I had written this code before but it is the property of my previous employer.  I could rewrite fairly easily because I have recently done the same thing in CRM 4 based on  code similar to this – http://www.stunnware.com/crm2/topic.aspx?id=JS26

but good news for me and other people out there JoshJWilliams has recently written the code and copied it to this forum post

so well done JoshJWilliams for perserving and solving the problem and thanks for copying the code up for the CRM community to use.

here is the code


function customerid_onchange(){
 // Get value of the selected customer account
 var lookupItem = Xrm.Page.getAttribute("parentcustomerid").getValue();

if (lookupItem != null)
 {
 //alert(lookupItem);

// Lookup Customer info
 var url = '/' + Xrm.Page.context.getOrgUniqueName() +
 '/_controls/lookup/lookupsingle.aspx?class=BrowseCustomerAddress&objecttypes=1071&browse=1&bindingcolumns=line1%2cpostalcode&parentType='
 + lookupItem[0].type + '&parentId='
 + lookupItem[0].id + '&ShowNewButton=1&ShowPropButton=1&DefaultType=1071';

// shows a modal window to select the addresses
 var selectedAddress = window.showModalDialog(url, null, 'dialogWidth:600px;dialogHeight:400px;resizable:yes');

// Validate address info in not null before continuing
 if (selectedAddress != null)
 {
 //alert(selectedAddress);
 var addressFields = selectedAddress.items;
 // we have the id of the address -now use the json to get the values in an array.
 sLookupValue = addressFields[0].id;
 //alert(sLookupValue);

var xml = "" +
 "<?xml version=\"1.0\" encoding = \"utf-8\"?>" +
 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
 decodeURI(GenerateAuthenticationHeader()) +
 " <soap:Body>" +
 " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
 " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryByAttribute\">" +
 " <q1:EntityName>customeraddress</q1:EntityName>" +
 " <q1:ColumnSet xsi:type=\"q1:ColumnSet\" >" +
 " <q1:Attributes>" +
 " <q1:Attribute>city</q1:Attribute>" +
 " <q1:Attribute>country</q1:Attribute>" +
 " <q1:Attribute>fax</q1:Attribute>" +
 " <q1:Attribute>line1</q1:Attribute>" +
 " <q1:Attribute>line2</q1:Attribute>" +
 " <q1:Attribute>line3</q1:Attribute>" +
 " <q1:Attribute>name</q1:Attribute>" +
 " <q1:Attribute>postalcode</q1:Attribute>" +
 " <q1:Attribute>primarycontactname</q1:Attribute>" +
 " <q1:Attribute>stateorprovince</q1:Attribute>" +
 " <q1:Attribute>telephone1</q1:Attribute>" +
 " </q1:Attributes>" +
 " </q1:ColumnSet>" +
 " <q1:Attributes>" +
 " <q1:Attribute>customeraddressid</q1:Attribute>" +
 " </q1:Attributes>" +
 " <q1:Values>" +
 " <q1:Value xsi:type=\"xsd:string\">" + sLookupValue + "</q1:Value>" +
 " </q1:Values>" +
 " </query>" +
 " </RetrieveMultiple>" +
 " </soap:Body>" +
 " </soap:Envelope>" + "";

xml = xml.replace(/:/g, ":");
 xml = xml.replace(///g, "/");

//window.clipboardData.setData("text", xml);
 var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
 xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
 xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
 xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
 xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
 xmlHttpRequest.send(xml);

var resultXML = xmlHttpRequest.responseXml;

//alert(xmlHttpRequest.responseText);
 var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
 oXmlDoc.async = false;

oXmlDoc.loadXML(resultXML.xml);

var businessEntities = oXmlDoc.getElementsByTagName('BusinessEntity');
 /*if (businessEntities[i].selectSingleNode('./q1:name') != null)
 {
 alert(businessEntities[0].selectSingleNode('./q1:name').nodeTypedValue);
 }
 alert(businessEntities[0].selectSingleNode('./q1:city').nodeTypedValue);
 alert(businessEntities[0].selectSingleNode('./q1:country').nodeTypedValue);
 alert(businessEntities[0].selectSingleNode('./q1:line1').nodeTypedValue);
 alert(businessEntities[0].selectSingleNode('./q1:postalcode').nodeTypedValue);
 alert(businessEntities[0].selectSingleNode('./q1:stateorprovince').nodeTypedValue);
 }
 }
 } */

for (i=0; i< 1; i++)
 {

if (businessEntities[i].selectSingleNode('./q1:name') != null)
 {

// Address Name Set
 Xrm.Page.getControl("address1_name").setDisabled(false);
 Xrm.Page.getAttribute("address1_name").setValue(businessEntities[i].selectSingleNode('./q1:name').text);
 Xrm.Page.getAttribute("address1_name").setSubmitMode("always");
 Xrm.Page.getControl("address1_name").setDisabled(true);

if (businessEntities[i].selectSingleNode('./q1:city') != null) {
 // Address City set
 Xrm.Page.getControl("address1_city").setDisabled(false);
 Xrm.Page.getAttribute("address1_city").setValue(businessEntities[i].selectSingleNode('./q1:city').text);
 Xrm.Page.getAttribute("address1_city").setSubmitMode("always");
 Xrm.Page.getControl("address1_city").setDisabled(true);
 }

if (businessEntities[i].selectSingleNode('./q1:country') != null){
 // Country set
 Xrm.Page.getControl("address1_country").setDisabled(false);
 Xrm.Page.getAttribute("address1_country").setValue(businessEntities[i].selectSingleNode('./q1:country').text);
 Xrm.Page.getAttribute("address1_country").setSubmitMode("always");
 Xrm.Page.getControl("address1_country").setDisabled(true);
 }

if (businessEntities[i].selectSingleNode('./q1:line1') != null){
 // Address Line 1 set
 Xrm.Page.getControl("address1_line1").setDisabled(false);
 Xrm.Page.getAttribute("address1_line1").setValue(businessEntities[i].selectSingleNode('./q1:line1').text);
 Xrm.Page.getAttribute("address1_line1").setSubmitMode("always");
 Xrm.Page.getControl("address1_line1").setDisabled(true);
 }
 if (businessEntities[i].selectSingleNode('./q1:line2') != null){
 // Address Line 2 set
 Xrm.Page.getControl("address1_line2").setDisabled(false);
 Xrm.Page.getAttribute("address1_line2").setValue(businessEntities[i].selectSingleNode('./q1:line2').text);
 Xrm.Page.getAttribute("address1_line2").setSubmitMode("always");
 Xrm.Page.getControl("address1_line2").setDisabled(true);
 }

if (businessEntities[i].selectSingleNode('./q1:line3') != null){
 // Address Line 3 set
 Xrm.Page.getControl("address1_line3").setDisabled(false);
 Xrm.Page.getAttribute("address1_line3").setValue(businessEntities[i].selectSingleNode('./q1:line3').text);
 Xrm.Page.getAttribute("address1_line3").setSubmitMode("always");
 Xrm.Page.getControl("address1_line3").setDisabled(true);
 }

if (businessEntities[i].selectSingleNode('./q1:postalcode') != null){
 // Address ZipCode set
 Xrm.Page.getControl("address1_postalcode").setDisabled(false);
 Xrm.Page.getAttribute("address1_postalcode").setValue(businessEntities[i].selectSingleNode('./q1:postalcode').text);
 Xrm.Page.getAttribute("address1_postalcode").setSubmitMode("always");
 Xrm.Page.getControl("address1_postalcode").setDisabled(true);
 }

if (businessEntities[i].selectSingleNode('./q1:stateorprovince')!= null){
 //Address State set
 Xrm.Page.getControl("address1_stateorprovince").setDisabled(false);
 Xrm.Page.getAttribute("address1_stateorprovince").setValue(businessEntities[i].selectSingleNode('./q1:stateorprovince').text);
 Xrm.Page.getAttribute("address1_stateorprovince").setSubmitMode("always");
 Xrm.Page.getControl("address1_stateorprovince").setDisabled(true);
 }

}// end if entity not empty
 }// end for i++

}// end if no address selected
 } // end of if no customer seelcted
 // end of new address selected function
 }