How to change default form based on dropdown JS and CRM? - javascript

Ok so what I am trying to do in CRM 2011 is to have a dropdown menu where it has two options: "Support" and "Prof. Services", this is for the Case entity. Now, I have two forms one named "Support" and one name "Prof. Services".
What I want to happen is that if a Case has the dropdown set to "Support" when it is opened it should open with the "Support" form and if the dropdown is set to "Prof. Services" it should open with the "Prof. Services" form.
I came across this article: http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/5ba919f7-9f7c-4abf-ba88-224951bb7c11 and used that code in a JScript web resource. Then on both of my forms I went to the Form Properties and added an OnLoad function setForm() (as in my JS code below). But this doesn't work. The right form is not showing for the right case/dropdown value. This is the code I am using: (any help debugging this would be much appreciated) *keep in mind I am beginner JS'er :)
function setForm() {
var currentForm= Xrm.Page.ui.formSelector.getCurrentItem().getId();
var Information;
var cType = Xrm.Page.data.entity.attributes.get('new_CaseType').getText().toLowerCase();
var forms = Xrm.Page.ui.formSelector.items.get();
var i = 0;
for (i = 0; i < forms.length; i++) {
if (forms[i].getLabel().toLowerCase()==cType) {
if (currentForm!=forms[i].getId()) {
forms[i].navigate();
}
return;
}
if (forms[i].getLabel().toLowerCase()=='information') {
Information=forms[i];
}
}
if (currentForm!=Information.getId()) {
Information.navigate();
}
}

For help with debugging I would suggest having a read of these fine articles:
How to Debug JScript in Microsoft Dynamics CRM 2011.
Debugging Script with the Developer Tools.
How-to series: Easily debug your CRM JavaScript code in IE8.

Related

Javascript broken after migrating from cognos 10.2.2 to cognos 11

I have migrated the reports from Cognos 10.2.2 to Cognos "11.0.13.1 LTS" version. The java script governing the prompt page is currently broken after migrating to 11. This is working well and good on 10.2.2.
Did something change on Cognos 11 or some functions that we are using is deprecated or something similar. Any rope would be really useful in diagnosing the issue.
We also put a ticket to IBM as well to identify what is going on
We tried editing the code and formatted the code in different ways and still getting the same behavior.
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}
var form = fW;
var ID=fW.elements["_oLstChoicesID"];
var SID=fW.elements["_oLstChoicesSID"];
ID.attachEvent("onclick", m_click);
function m_click()
{
for(i=0;i<fW._oLstChoicesID.length;i++)
{
fW._oLstChoicesID[i].selected=false;
fW._oLstChoicesID[i].disabled=true;
}
for(i=0;i<fW._oLstChoicesSID.length;i++)
{
fW._oLstChoicesSID[i].disabled=false;
}
}
I want the second List "SID" to be disabled when any of the elements in the ID is selected.
I think the "FormWarpRequest" stuff is a holdover from Cognos 8. It may not work in Cognos 11.0.x. You should be using cognos.Report.getReport("_THIS_"); in Cognos 10.2.2 (https://www.ibm.com/support/knowledgecenter/en/SSEP7J_10.2.2/com.ibm.swg.ba.cognos.ug_cr_rptstd.10.2.2.doc/r_prmpt_api_cognos_report.html#cognos.report). That should still work in Cognos 11.0.x, but you'll want to begin moving to the new coding style using RequireJS (see https://www.ibm.com/communities/analytics/cognos-analytics-blog/updated-javascript-samples-for-ibm-cognos-analytics-11-0-10/ and https://public.dhe.ibm.com/software/data/sw-library/cognos/mobile/scriptable_reports/index.html) and changing the Run with full interactivity property to Yes to take advantage of the new features.

Add dynamic title for Worklight tab bar item

I am using worklight tab bar in my hybrid app,I am getting tab bar displayed in html page,i need to apply translation for tab bar title,is it possible to give dynamic value for tab bar item title.can anyone help me in solving this...
In the use case of translation you would need to check for the device locale/language using API methods such as WL.App.getDeviceLocale or WL.App.getDeviceLanguage when the application launches and before you display the tabbar; based on the language check response, load the appropriate labels for the desired language.
See related question: IBM Worklight - WL.App.getDeviceLanguage() API method does not return correct language code in iOS
Example
The below was tested in iOS, but should be applicable for Android as well.
See the related question I linked to above.
In common\main.js:
var myLabel1, myLabel2;
function wlCommonInit(){
if (WL.App.getDeviceLanguage() == "en") {
/* Using English */
myLabel1 = "tab 1";
myLabel2 = "tab 2";
}
if (WL.App.getDeviceLanguage() == "he") {
/* Using Hebrew */
myLabel1 = "טאב 1";
myLabel2 = "טאב 2";
}
WL.TabBar.init();
WL.TabBar.setVisible(true);
WL.TabBar.addItem("tabOne", function() {}, myLabel1, {image:"images/myimage.png"});
WL.TabBar.addItem("tabTwo", function() {}, myLabel2, {image:"images/myimage.png"});
}
In this image you can see the lables in Hebrew, because my device's region is in Hebrew.

Browser Link and Web Forms (Design mode doesn't work for ASP.NET Web Forms)

I have been playing around with the new Browser Link feature in visual studio 2013. However, I am not able to get the "Design Mode" feature working for "Web Form" pages. It works fine when I am browsing a MVC page. However, as soon as I add a web form to the project, it get an alert in my browser saying that
"Design mode doesn't work for ASP.NET Web Forms".
I can also inspect and refresh the page (from the Browser Link Dashboard).
I tried to debug the JavaScript code injected into the browser to see where it's happening. If you turn your F12 developer on, and search for "Design Mode", you will see it in a js file (the path looks like "/foo/browserlink").
map = browserLink.sourceMapping.getCompleteRange(target);
if (map && map.sourcePath) {
if (isValidFile(map.sourcePath.toLowerCase())) {
current = target;
$(target).addClass(selectedClass);
browserLink.sourceMapping.selectCompleteRange(current);
}
else {
enableDesignMode(false);
alert("Design Mode doesn't work for ASP.NET Web Forms");
}
}
and then the "isValidFile" has the following body
function isValidFile(sourcePath) {
var exts = [".master", ".aspx", ".ascx"];
var index = sourcePath.lastIndexOf(".");
var extension = sourcePath.substring(index);
for (var i = 0; i < exts.length; i++) {
if (exts[i] === extension)
return false;
}
return true;
}
How can I get this working for my Web forms application?
So the injected javascript is actively looking for web-form based pages (aspx, ascx, master) and firing the alert accordingly. I guess it means exactly what it says!
I couldn't find any additional documentation on this so I tweeted Mads Kvist Kristensen (Web Tools team) for clarification. Not sure if this will be added at a later date? Looks like an awesome feature would love to use it in my web forms app?

Open Sharepoint folder with windows explorer from CRM 2011

I've been struggling with this issue for a while now,
and hope maybe someone in the community can provide a resolution.
I have a requirement which is to put a button on the a CRM account form which will have the same logic as the Open With Explorer button in a Sharepoint document library. The logic is required as the users have to do several click in order to get to this button, and open the required account's folder in windows explorer, which are:
Click Documents in navigation of the form, to open SP integration
Click documents in the SP view
Click library
Click the Open With Explorer button
The CRM is integrated with Sharepoint, and when the folder is opened in windows explorer it has the following sample link
http://{sharepoint}/CRM/7F9F72A1-4591-E011-AC6C-00155D773703/Documents/
Where the GUID 7F9F72A1-4591-E011-AC6C-00155D773703, is the account id in CRM.
From my research i have found that the javascript function that achieves this is
NavigateHttpFolder from the sp.js in Sharepoint.
From this function, and this link About Web Folder Behaviors
I've completed the following function.
var httpFolderDiv = document.createElement("SPAN");
function NavigateToFolder() {
document.body.appendChild(httpFolderDiv);
httpFolderDiv.onreadystatechange = NavigateToFolder;
httpFolderDiv.id = "navDiv";
httpFolderDiv.addBehavior("#default#httpFolder");
if (httpFolderDiv.readyState == "complete") {
httpFolderDiv.onreadystatechange = null;
var link = "";
var account = "";
var accountid = "";
var id = Xrm.Page.data.entity.getId().replace("{", "").replace("}", "");
link = "http://{sharepoint}/CRM/" + id + "/Documents/";
try {
httpFolderDiv.navigateFrame(link, "_blank");
} catch (c) {
alert(c.toString());
}
}
}
This function opens up the folder from Sharepoint in windows explorer, but with limitation if only that folder was previously opened directly from Sharepoint.
I believe that the logic I am missing in the code, is that I don't do mapping of the folder, the way sharepoint does.
I am aware that this folder can be mapped manually as a network drive, Connecting WebDAV Server Using Web folders, but this will not do the trick for me as this will have to be done on every client.
How can I achieve this by grabbing the complete logic from SP, or maybe running a console command from javascript to map the folder prior to opening it with the above function.
I know it's been a while, since this has been posted, but I stumbled upon it while searching for the exact same problem.
Here's what worked for me in SharePoint 2013:
<a href='#' onClick="javascript:CoreInvoke('NavigateHttpFolder', '[path to site]/[library name]/', '_blank');">
Click to open in Explorer
</a>
It's essentially the same function used by SharePoints own functionality.

CRM 2011 "This page is accessing information that is not under its control"

I have the following javascript on a CRM form which is used to grab a local copy of the Subject entity records:
function refreshSubjects() {
sgc_subjectCache = [];
var options = "$select=Title,SubjectId,ParentSubject";
SDK.REST.retrieveMultipleRecords("Subject", options, refreshSubjectsCallback, function(error) {
alert( error.message );
}, refreshSubjectsComplete);
}
But this results in the annoying "this page is accessing information that is not under its control" dialogue.
I'm not sure why as there is no cross-domain posting going on.
Is there a way to suppress this without compromising browser security?
I found the answer: http://social.microsoft.com/Forums/en-IE/crmdevelopment/thread/6e050347-e584-47c2-aab1-8fdf74e8ef1e
Basically, the domain was correct in the database but I was using "localhost" in my web browser, whereas the SDK was using the FQDN.
Calling the site via the FQDN in the browser removed the problem!

Categories

Resources