Xrm.Navigation.openForm not honouring formid - javascript

I'm trying to follow the examples found here that explain how to use Xrm.Navigation.openForm method to open a CRM form for a new entity.
My target entity has multiple forms and I'm trying to specify the form ID in the entityFormOptions object as described in the link above. I've copied the relevant text here (with the relevant line in bold):
entityFormOptions
Entity form options for opening the form. The
object contains the following attributes:
cmdbar: (Optional) Boolean. Indicates whether to display the command bar. If you do not specify this parameter, the command bar is displayed by default.
createFromEntity: (Optional) Lookup. Designates a record that will provide default values based on mapped attribute values. The lookup object has the following String properties: entityType, id, and name (optional).
entityId: (Optional) String. ID of the entity record to display the form for.
entityName: (Optional) String. Logical name of the entity to display the form for.
formId: (Optional) String. ID of the form instance to be displayed.
height: (Optional) Number. Height of the form window to be displayed in pixels.
navBar: (Optional) String. Controls whether the navigation bar is displayed and whether application navigation is available using the
areas and subareas defined in the sitemap. Valid values are: "on",
"off", or "entity".
However this doesn't seem to work for me.
The ID of my form is 375DE297-C0AF-4711-A811-5F1663FAE5DA
Here's my code:
var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
entityFormOptions["formId"] = "375DE297-C0AF-4711-A811-5F1663FAE5DA";
Xrm.Navigation.openForm(entityFormOptions);
The new entity form opens; however it uses the default form, not the specified form.
I am running as a System Administrator and I have confirmed that I have access to all the forms for the specified entity so I don't think it is a form-security issue.
Has anyone tried this method of opening forms in Dynamics 365?

That's looks like mistake in docs or bug in Dynamics.
Previous implementation (v8 and before) took formid in parameters object: https://msdn.microsoft.com/en-us/library/jj602956.aspx#openEntityForm
Although current documentation states that formId must be set in entityFormOptions it isn't actually honoured. But it is honoured when you put it to good old formParameters.
Thus this does the trick:
var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
var formParameters = {};
formParameters ["formid"] = "375DE297-C0AF-4711-A811-5F1663FAE5DA";
Xrm.Navigation.openForm(entityFormOptions, formParameters);
P.S. Note that lowercase "formid".

This may be a little late but hopefully will help someone else.
The documentation is correct. You can supply formId as shown. You only need to make sure that form is added to the Model Driven App in App Designer (You add the form by checking it on the panel on the right)
var pageInput = {
pageType: "entityrecord",
entityName:"icon_case",
entityId: recordId,
formId: v_formId
};

we can also use the below code to open a particular entity form:
var entityFormOptions = {};
entityFormOptions["entityName"] = "nrw_contact";//Logical name of the entity
entityFormOptions["entityId"] = "nrw_contact_ID"; //ID of the entity record
entityFormOptions["formId"] = "CF8D885B-256D-43E6-8776-CBBB7AA88EF5"; //FormId
Xrm.Navigation.openForm(entityFormOptions);
Please refer this link for more details : https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-navigation/openform

Related

How come javascript is recognizing that my control is now holding an array?

I'm working on small MVC application that is "sending emails", and at the begining I used dropdown to choose only 1 receiver, but after that I added multiple class to my dropdownList and when I choose 2-3 receivers and when I tried to debug this code which I used with only one receiver :
$("#SubmitEmail").click(function () {
var Receiver = $('#ReceiverID').val();
var Subject = $('#subject').val();
var Body = $('#content').val();
var obj = { 'Receiver': Receiver, 'Subject': Subject, 'Body': Body };
SendEmail(obj);
});
I realized that var Receiver which I used to store receiverId, become an array acctually, and I'm wondering how come javascript adapted soo cooooool so it recognized that I've selected few items there, and it become an array so I simply looped it (modified my code):
$("#SubmitEmail").click(function () {
var Receivers = $('#ReceiverID').val();
for (var i = 0; i < Receivers.length; i++) {
var Receiver = Receivers[i];
var Subject = $('#subject').val();
var Body = $('#content').val();
var obj = { 'Receiver': Receiver, 'Subject': Subject, 'Body': Body };
}
SendEmail(obj);
});
And everything was cooool, so I'm simply wondering how come js knows it all?
From the jQuery docs on val():
When the first element in the collection is a select-multiple (i.e., a
select element with the multiple attribute set), .val() returns an
array containing the value of each selected option.
So it's actually jQuery magic, not JavaScript magic.
You can see the actual source code for val() here. It's a function that calls the get hook of the select element, which actually does a loop over the selected options.
Javascript is cool as you state, but in this example it, in fact, is a Jquery implementation flexibility which returns array of objects for dropdown. see http://api.jquery.com/val/ for details.
This is how jQuery works. See .val() function:
http://api.jquery.com/val/
Scroll down for this example:
Get the single value from a single select and an array of values from a multiple select and display their values.

Adding "values" to a texfield in jquery/js

When writing a new email, I've got a modal(pop-up window in boostrap) that shows a list of contacts. When I select (through checkboxes) a couple of contacts, the selected ones are written into a checkbox. Problem is I'm just writing the lastone I select instead of all of the selected ones.
If you need further explanation please ask. (Sorry for my english)
$("#tblContacto").on("click", ".ck", function(event){
if($(".ck").is(':checked')) {
selected_index = parseInt($(this).attr("alt").replace("Check", ""));
var contacto = JSON.parse(tbContactos[selected_index]);
$("#txtDestinatarios").val(contacto.Email);
} else {
$("#txtDestinatarios").val("");
}
});
Assuming that you want to add all E-Mails into a textfield with id txtDestinatariosthe cause of your Problem is the usage of the $("#txtDestinatarios").val(); function.
Calling val() with an argument sets (and thus overwrites) the value within the textfield. (See demo at http://api.jquery.com/val/#val2)
You would have to first retrieve the value of the textfield using code like var currentValue = $("#txtDestinatarios").val() and then add/remove the E-Mail from/to the string before setting the resulting string back as the value.
If you want to set all selected items in the checkboxes into Textfiled you can use the following line of code :-
$("#txtDestinatarios").val( $("#txtDestinatarios").val()+ ","+contacto.Email);

Implement a Custom Search Engine built on top of google.com

I want to build a webpage/ custom search engine that will take user input and then query google for the results, except that with a number of keywords I want to append some predefined strings that ( will be stored in a dictionary/file..).
I tried using a form and then submitting query to google, but I want to do it as beautifully (and much the same way) as these people have done.
They just append Zlatan at the beginning , I want to append variable strings.
To show you what I've tried, here is the link to GitHub: https://github.com/google/google-api-php-client/blob/master/examples/simple-query.php
Any useful links, knowledge , suggestions, steps would be heartily appreciated.
This is how they do it. Just do the same but append any word from you list of words as you like. It's not clear how you're supposed to select what words to add. Specify that and we can be more helpful.
var form = document.querySelector('form');
var input = document.getElementById('field');
form.addEventListener('submit', function(ev) {
ev.preventDefault();
var redirect = 'https://google.com/search?q=zlatan+' + input.value;
window.location = redirect;
});

crm 2011 xrm.page.getattribute returns null when there is value

I'm not really skillful with JScript but I've written the following code within a function webResource that is supposed to run when the form loads (OnLoad)
var creationDateName = "createdon";
var today = new Date();
var creationDateAttr = Xrm.Page.getAttribute(creationDateName);
if(creationDateAttr!=null)
{
/* Some more code */
}
The problem is that Xrm.Page.getAttribute(creationDateName) returns null when there is a value on the field (the field is not being displayed in form but when looking up it has a value). Funky thing about it is that in my test organization the same code worked like a charm, but when I copied and paste it on the production organization to release the solution it doesn't work properly that's what confuses me a lot. Any idea what might be happening?
You need to use getValue to return the value in the field. Your code is merely checking that the field exists on the Page.
You also need to be aware that in Create mode, these values are not set, so you can't retrieve them. In Update mode they will work. So you need to check that the Page is in Update mode too:
var formType = Xrm.Page.ui.getFormType();
if (formType === 2) // Update
{
var creationDate = Xrm.Page.getAttribute(creationDateName).getValue();
}
it gives you the attribute not the value..
to get the value you have to write code as below
var creationDateAttr = Xrm.Page.getAttribute(creationDateName);
var valueDateAttr=creationDateAttr.getValue();
OR
var creationDateAttrValue = Xrm.Page.getAttribute(creationDateName).getValue();
hope this will help
Silly me, I forgot to add the field I was looking for that's why it return null but thanks to Donal for the answer, actually I was trying to verify if the field was full or was null. Thanks

Type Casting in Apps Script

First time on StackOverFlow!
I am working on building an app that takes in a value through a UI Form TextBox. Once that form is submitted it calls a method that then appends a "/" to the value. The problem is that .append() is not available, because getElementById() returns a GenericWidget object and thus cannot be operated on as if it were a string. I have tried type casting it use .toString() in the var userinput = app.getElementById('input').toString; call and afterward using userinput = userinput.toString.
I have been working with Apps Script for about a month and a few days now and I think that casting to a different type other than GenericWidget would be helpful for anyone who wants to modify a value in a type specific way after passing the value to another method.
I have also done a good bit of research trying to find a solutiong for my problem but like a couple times in the past working with Apps Script I find that since it is a younger language there isn't as much helpful information as there is with languages like Javascript, HTML, and XML. Any help is appreciated.
You have to get the textBox value using e.parameter.textBoxName an then re-assign a value to the textBox. A short example will be more explicit
function doGet(){
var app = UiApp.createApplication();
var textbox = app.createTextBox().setName('txt').setId('txt')
// add other elements, handlers, callBackElements, etc...
}
function changetext(e){
var app = UiApp.getActiveApplication();
var textBoxValue = e.parameter.txt ; // get the value in the text box
var txtBoxWidget = app.getElementById('txt') ; get the widget by its ID
txtBoxWidget.setText(textBoxValue+'/'):// assign the modified value
return app ;// update the UI with new value
}

Categories

Resources