Hi all, it's been a loooong time since i last updated this blog.. But here's a new nice tip :)
Microsoft have not given us the easiest way of updating fields on FORMS based on the new processbars feature on FORMS, but here's one way to do it With Javscript.. Supported!
Should work on opportunities.. AFTER YOU INSERT YOUR GUID's FOR
1. Field "processid"
2. Field "stageid"
3. Change name of "salesstage"
(Needed in setSalesStage function)
/* Script Entry Point */
function OnCrmPageLoad() {
var FormTypes =
{
Undefined: 0,
Create: 1,
Update: 2,
ReadOnly: 3,
Disabled: 4,
QuickCreate: 5,
BulkEdit: 6
}
runAlways();
switch (Xrm.Page.ui.getFormType()) {
case FormTypes.Create: OnNewFormLoad(); break;
case FormTypes.Update: OnUpdateFormLoad(); break;
case FormTypes.ReadOnly: OnReadOnlyFormLoad(); break;
case FormTypes.Disabled: OnDisabledFormLoad(); break;
case FormTypes.QuickCreate: OnQuickCreateFormLoad(); break;
case FormTypes.BulkEdit: OnBulkEditFormLoad(); break;
case FormTypes.Undefined: alert("Error"); break;
}
}
/* Implement each Form Type you wish to address */
function runAlways() {
onchange();
Xrm.Page.data.entity.addOnSave(addToOnSave);
}
function OnNewFormLoad() {
setSalesStage('new');
}
function OnUpdateFormLoad() {}
function OnReadOnlyFormLoad() { }
function OnDisabledFormLoad() { }
function OnQuickCreateFormLoad() { }
function OnBulkEditFormLoad() { }
/******************** OnChange and OnSave functions ***************************/
function onchange() {
//Add all fields who should have OnChange triggers
Xrm.Page.data.entity.attributes.get("prefix_fieldname").addOnChange(examplefunction);
}
function addToOnSave() {
//Check to see if stageid has changed
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes) {
var attribute = attributes[i];
if (attribute.getIsDirty()) {
if (attribute.getName() == 'stageid') {
//Update Probability field - send a "dummy parameter"
setSalesStage('dummy');
}
}
}
}
/*************** End OnChange and OnSave functions ***************************/
/* --------------- Private functions ---------------------*/
function examplefunction() {
//No Operation
}
function setSalesStage(check) {
/*
UNIKE FOR EACH PROSESS AND CRM ORGANIZATION
Notes of GUID's steps in Prosess ID = 'bfc01b1c-9741-43b2-a016-3a41d91c234a' Display: "Solution Selling" on entity: opportunity
10% - 85bdfa9d-f067-42d4-82c3-0e1fd09f2b19
20% - 6a2020c4-7d10-28e3-1898-138b6c075259
40% - ae0c9ae4-55eb-cd1c-44ab-872d4aca4338
60% - 16b99584-143d-04ad-61c9-2b6a809e5608
80% - 93e08965-2e2a-4674-0e57-ec88633a0940
90% - 3a516491-d7cd-6cb1-a3e0-61be68c1857c
*/
var prosessId = Xrm.Page.getAttribute("processid");
var stageid = Xrm.Page.getAttribute("stageid");
var prob = Xrm.Page.getAttribute("salesstage");
//Check if new record
if (check == 'new') {
//sets first process name
prob.setValue('10% - Qualification');
}
//Not a new record, then it's an existing record
else {
if (prosessId.getValue() == 'bfc01b1c-9741-43b2-a016-3a41d91c234a') {
switch (stageid.getValue()) {
case '85bdfa9d-f067-42d4-82c3-0e1fd09f2b19':
//setter sannsynlighet
prob.setValue('10% - Qualification');
break;
case '6a2020c4-7d10-28e3-1898-138b6c075259':
prob.setValue('20% - Pain and Need');
break;
case 'ae0c9ae4-55eb-cd1c-44ab-872d4aca4338':
prob.setValue('40% - Proof of Concept');
break;
case '16b99584-143d-04ad-61c9-2b6a809e5608':
prob.setValue('60% - Closing');
break;
case '93e08965-2e2a-4674-0e57-ec88633a0940':
prob.setValue('80% - Offering accepted');
break;
case '3a516491-d7cd-6cb1-a3e0-61be68c1857c':
prob.setValue('90% - Contract signing');
break;
default:
alert("An error has occured!");
}
}
}
}
/* ------------ End Private functions------------------*/
Tuesday, January 21, 2014
Wednesday, September 5, 2012
How to open CRM FORMS and Web Resources correctly!?
Some CRM implementations require the use of custom Jscript to pop open a new entity form window or a window displaying an existing record in CRM. Previously, there was no “supported” way to do this, since we had to use the window.open Jscript object which relies on the use of the Document Object Model (DOM).
Update rollup 8 provides new SDK functions which CRM configurators can use to open CRM forms and web resources in a nice supported way.
The Old Way - Making the URL static with parameters:
Here is an example of how to pop open an existing Account using Jscript:
function popAccount() {
var accountId = "8FB2CCE4-20E4-E111-9700-00155D042F0D";
var url = Xrm.Page.context.getServerUrl() + "/main.aspx?etn=account&id=" + accountId + "&pagetype=entityrecord";
window.open(url);
}
Here is an example of how to pop open an HTML Web Resource using Jscript:
function popHTML() {
var url = Xrm.Page.context.getServerUrl() + "//WebResources/iaf_/html/test.html";
window.open(url);
}
Although these methods do work, they could potentially break as new rollups are applied to your system, or when CRM 2011 is available on multiple browsers.
The New way - New functions :)
function popAccount() {
var accountId = "8FB2CCE4-20E4-E111-9700-00155D042F0D";
Xrm.Utility.openEntityForm("account", accountId);
}
If we wanted to pop open a new Account form, we can exclude the ID parameter.
Here is an example of how to pop open an HTML Web Resource using Jscript:
function popWebResource() {
var webResourceName = "iaf_/html/test.html";
Xrm.Utility.openWebResource(webResourceName);
}
Please note this is only a few of New functions released in rollup 8 related to "Xrm.Utility" :)
Happy Xrm'ing!
Source: http://blogs.msdn.com/b/crm/archive/2012/07/18/new-xrm-utility-functions-in-update-rollup-8-for-microsoft-dynamics-crm-2011-and-microsoft-dynamics-crm-online.aspx
Wednesday, May 30, 2012
The view: "Products in Parent Price List" is gone!?
This article talks about a parent look view which is never visible after the “Display search box in lookup diaglog” is checked while customizing Opportunity Product Entity in CRM 2011. There is an easy workaround to get back to old view.
The following are steps to achieve that
Happy XRM'ing!
How do I revert to old view?
If you’re thinking that you can just go and uncheck. No then that’s not a solution. We will need to revert through a customization tweak. The reason for this and by now CRM has reset the view id. Hence it shows a different view.The following are steps to achieve that
- Go to Settings > Solutions
- Add new Solution and provide a valid name to it.
- Save the solution.
- Now add existing entity, “Opportunity Product”
- Export the solution as unmanaged
- Open the unmanaged solution in notepad and locate the following:
- Replace {8BA625B2-6A2A-4735-BAB2-0C74AE8442A4} with {BCC509EE-1444-4A95-AED2-128EFD85FFD5}
- Save the changes
- Zip the files and import the solution back to your environment
- Publish the customizations
- Refresh the CRM in your browser
- You will see the correct view.
Happy XRM'ing!
Subscribe to:
Posts (Atom)