Wednesday, June 30, 2010

Jscipt for Color Picklist Color

Changing the color of a single option in a picklist

You can change the color and background color of an option element using the following syntax:

//TODO: Replace with the schema name of the picklist in question.
var list = crmForm.all.;

//using the first option here, you need to find the one you need.
var option = list.options[0];

//Set the background color to red.
option.style.backgroundColor = "#FF0000";

//Set the text color to white.
option.style.color = "#FFFFFF";

Thursday, June 3, 2010

Calling Workflow from Jscript

CRM 4.0: Use JavaScript execute/call/launch CRM Workflow
I have a question from my colleague: How to use JavaScript execute workflow in CRM 4.0? The question also repeats very often in CRM Forums, no answer so far.

In CRM 3.0, Mitch Milam has described how to Launching a Workflow Rule from JavaScript, it works great. However, in CRM 4.0, the class: ExecuteWFProcessRequest has been deprecated, so it won’t work in CRM 4.0. Although there are many ways to launch a workflow, if you want to run it through JavaScript, here’s the trick:

/* the function */ExecuteWorkflow = function(entityId, workflowId){ var xml = "" + "" + "" + GenerateAuthenticationHeader() + " " + " " + " " + " " + entityId + "" + " " + workflowId + "" + " " + " " + " " + "" + ""; var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false); xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute"); xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlHttpRequest.setRequestHeader("Content-Length", xml.length); xmlHttpRequest.send(xml); var resultXml = xmlHttpRequest.responseXML; return(resultXml.xml);}/* call */var theWorkflowId = "3FD2DD58-4708-43D7-A21B-F0F90A0AA9F2"; //change to your workflow IdExecuteWorkflow(crmForm.ObjectId, theWorkflowId);