Archive
Switch Business Process Flow using Jscript based on CRM form’s field value
Recently we got a requirement to switch the Business process on Case form based on ‘Case Origin’.
Its easily achievable using Jscript “setActiveProcess” method.
Xrm.Page.data.process.setActiveProcess(processId, callbackFunction);
- ‘processId‘ is the GUID of the ‘Business Process Flow’. You can copy the GUID from URL.
- Go to ‘Settings –> Processes’ open the ‘Business Process Flow’ and copy the value from ‘id’ parameter, between %7b %7d
- ‘callbackFunction’ is your custom JScript function name which gets triggered post ‘Business Process’ switch.
Below are the scenario and steps.
- I have 3 Active Business Process Flows on my ‘Case’ entity.
- ‘Business Process Flows’ are Security Role Based, so if my user has access to all 3 ‘Business Process Flows’, he can switch the process using ‘Switch Process’option.
- In my scenario, ’Switch Process’ should happen based on ‘Case Origin’ field.
- If ‘Case Origin’= Phone; Set “Business Process1”
- If ‘Case Origin’= Email; Set “Business Process2”
- Below is the script
function onload() {
// If not new Case form
if (Xrm.Page.ui.getFormType() != 1) {
// Read Origin Option text
var origin = Xrm.Page.data.entity.attributes.get(“caseorigincode”);if (origin && origin.getText()) {
var caseOrigin = origin.getText();// Get Business process flow id
var processFlow1Id = “6CD44946-0DC5-47E3-9B62-6D7309254710”;
var processFlow2Id = “0B3A94CD-CD43-4F49-A9A3-93C4AC684CFA”;// Get Current Active Process Id
var activeProcess = Xrm.Page.data.process.getActiveProcess();
var currProcessId = activeProcess.getId();if (caseOrigin.toLowerCase() == “phone”) {
// Change the process only if current Active Process not the Target one
if (currProcessId.toLowerCase() != processFlow1Id.toLowerCase()) {
// Switch to the “Process Flow 1”
Xrm.Page.data.process.setActiveProcess(processFlow1Id, myCallBack);
}
} else if (caseOrigin.toLowerCase() == “email”) {
// Change the process only if current Active Process not the Target one
if (currProcessId.toLowerCase() != processFlow2Id.toLowerCase()) {
// Switch to the “Process Flow 2”
Xrm.Page.data.process.setActiveProcess(processFlow2Id, myCallBack);
}
}
}
}
}// Call back function post Process flow switch
function myCallBack(response) {
if (response == “success”) {
alert(“BPF changed !!!”);
// Save the form
Xrm.Page.data.entity.save();
}
else {
alert(“Error changing BPF!!!”);
}
}
How do I use the script?
- Copy the script and create a new ‘Web resource’ in CRM and add to ‘Case’ form.
- Register ‘onload()’ function on form onload event.
- Publish the Customizations.
- Open the Case record and based on ‘Case origin’ system auto switches to the Business process Flow.
Key points on multiple ‘Business process flows’:
- You can have up to 10 active business process flows per entity.
- You can associate business process flows with security roles so that only people with those security roles can see or use them.
- In case of multiple Active ‘Business process flows’, the first activated business process flow in that list is the one that will be applied by default.
- Each record can have only one business process flow at a time.
- If someone’s security roles do not allow them to use a specific business process flow, the current business process flow will be visible, but disabled.
🙂
Build Auto Complete Text Box using Jscript – CRM 2016
In CRM 2016, we got showAutoComplete and hideAutoComplete methods to configure the auto-completion experience in text controls in forms.
In this article, I am going to configure “Auto Complete” feature for my “Locality” text box on my Account form.
JScript:
function suggestLocality() {
// List of sample Locality names to suggest
accounts = [
{ name: ‘AA Street’, code: ‘A01’ },
{ name: ‘AB Street’, code: ‘A02’ },
{ name: ‘AC Street’, code: ‘A03’ },
{ name: ‘Benetten street’, code: ‘A04’ },
{ name: ‘Beverly Hills’, code: ‘A05’ },
{ name: ‘City Street’, code: ‘A06’ },
{ name: ‘City Power & Light’, code: ‘A07’ },
{ name: ‘Aruna Street’, code: ‘A08’ },
{ name: ‘Winery Street’, code: ‘A09’ },
{ name: ‘Coho Vineyard & Winery’, code: ‘A10’ },
{ name: ‘Zeebra Street.’, code: ‘A11’ }
];var localityKeyPress = function (ext) {
try {
var userInput = Xrm.Page.getControl(“raj_locality”).getValue();
resultSet = {
results: new Array(),
commands: {
id: “sp_commands”,
label: “Explore CRM”, // Help link text
action: function () {
window.open(“http://rajeevpentyala.com”); // Help link URL
}
}
};// Read the ‘Text’ entered in Locality field.
var userInputLowerCase = userInput.toLowerCase();
for (i = 0; i < localities.length; i++) {
if (userInputLowerCase === localities[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {
resultSet.results.push({
id: i,
fields: [accounts[i].name]
//, icon:<url> — Its an option field. You can show icon next to the Auto populated text.
});
}
if (resultSet.results.length >= 10) break;
}if (resultSet.results.length > 0) {
// If matches found; Show the Auto complete text area with matched localitites (i.e., Up to 10)
ext.getEventSource().showAutoComplete(resultSet);
} else {
// If no match found; Hide the Auto complete text area.
ext.getEventSource().hideAutoComplete();
}
} catch (e) {
alert(“Error while auto complete – ” + e.description);
}
};// Attach Key Press event to ‘Locality’ text box
Xrm.Page.getControl(“raj_locality”).addOnKeyPress(localityKeyPress);
}
How do I use it:
- Copy the “suggestLocality” function and create a web resource in CRM.
- Register the “suggestLocality” function on onload event of Account form.
- Publish the Customization’s.
- Open an Account and start typing in “Locality” text box.
- You can extend the script by instead of hard coding Localities, you can read from any existing entity and populate the list.
Important Notes on Auto Complete feature:
- “Auto Complete” show up to 10 matching strings in a drop-down list as users press keys to type character in a specific text field.
- These methods aren’t supported for the CRM mobile clients (phones or tablets).
🙂
Task Flow – CRM 2016
- “Task Flow” is a new feature available with CRM 2016 online update and is currently on preview mode.
- Task flows are targeted for phones or tablets.
- You can configure set of steps, where user perform day to day and package that as a ‘Task Flow’.
- “Task Flows” are somewhat similar to Dialog, which helps User with guided navigation of common tasks, but for Phone and Tablets.
In this article I am going to create a simple ‘Task Flow’ to capture Contact’s address along with a ‘Business Rule’.
Enable the preview feature:
- Task flows are a preview feature in CRM Online 2016 Update. So we need to first enable the feature.
- Go to Settings -> Administration -> System Settings -> Preview
- Agree the License terms and select the preview feature.
- After enabling ‘Task Flow’ feature, you will get a new ‘Business Process Type’, if you choose ‘Business Process Flow’.
Create Task Flow
- Go to Settings -> Processes -> New -> ‘Business Process Flow’
- Select “Business Process Type”, “Run process as a task flow (Mobile only)”
- I selected entity as “Contact”
- I named my Task Flow as “Contact Address Capture Task”
Configure your ‘Task Flow’
- As I want to capture my Contact’s Address details, I configured my ‘Task Flow’ with below fields.
Configure ‘Business Rule’
- I want ‘Phone number’ mandatory, if my Contact does not specify ‘City’.
- So I configured the Business Rule as below
Save and Activate.
Check the ‘Task Flow’ on Mobile client
- Open the ‘Dynamics CRM Application’ on Mobile
- You find an Icon on left corner, which shows all the available ‘Task Flows’
- Click on the Icon and choose the “Contact Address Capture Task”.
- Since “Task Flow” was configured on ‘Contact’ entity, I got ‘Contact’ search screen.
- I picked up the Contact which i want to update the Address details.
- It shows up the fields I configured along with ‘Business Rule’ (‘Phone’ become Required since ‘City’ is blank)
- I provided the details and click ‘Done’ to save the details.
🙂
System.Web.HttpUnhandledException – While opening a CRM record
Other day we were getting “Unexpected” exception while opening a ‘Contact’ record.
There were no error details to check at application level.
When I verified my CRM application server’s Event viewer, there was below error log
Exception of type ‘System.Web.HttpUnhandledException’ was thrown.
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Index was outside the bounds of the array.
Fix:
- By resetting the IIS on CRM application servers solved the issue.
Reason:
- Not sure what caused this exception, as nothing had been customized on Contact entity.
🙂