how to pass the executionContext on the Ribbon workbench for a HomePageGrid - dynamics-crm

I have been able to pass the formContext to the javascript function that I call from the ribbon when I call it from a Form button, but the same trick when calling from the HomePageGrid pass me a null value.
I use in both cases the Primary Control CRM parameter as stated in multiple places.
You can see on the left side how my PrimaryControl CRM parameter is passing a null value when selecting an item on the Grid. On the right side you can see how my PrimaryControl CRM parameter is passing the formContext correctly.
is it there any way to pass the executionContext/formContext/Context?. As you can see I have tried that is the Primary Control value is null to pick up Xrm.page.context and xrm.ui.getglobalContext.... and still doesn't work.
Any idea of what to do?
This is the configuration in the Ribbon Workbench
Updated for minohimself:
I have set the SelectedControl in the Ribbon and I am receiving on the first parameter the Mscrm.GridControl. And I dont see the formContext as you see it.
I might be doing something wrong, because it is obvious that you are able to see the context? can you point me in the right direction?
What I can see from your javascript code is that you have a theia.button which has a function called ExecuteActionWithErrorMessage that receives at least 4 parameters, including objectid, formContext, entityName, and actionName).
In my case my function is called and should receive the formContext and a yes/no (T/F) statement to decide how to manage the security roles.
So, should I include your four parameters, so I can retrieve as well the objectid, formcontext, entityname and actionname?
Thanks for your quick turn around and help.
UPDATE 2:
Here you can see my Ribbon Workbench Command
and here you can see my Debugger View:
as you can see what you see it is not what I see. I am on a Ms. Dynamics CRM v9.0.15.9 (version 1612) on-premises.

Have you tried SelectedControl parameter ? that one is ment for subgrids. The one youre using is used on Forms. ;)
I just tested what you get when you pass SelectedControl

Related

Is there a way to enable Javascript on bulkEdit form from Dynamics 365 CRM?

Multiple required fields from bulk edit form are not displayed. The labels for that fields appear on form but the textboxes don't appear. I think this happens because we have scripts that run for that fields. I tried to edit customizations.xml and to put BehaviorInBulkEditForm = "Enabled" but it is not working. Is there another way to enable javascript?
As per the Form XML schema, the BehaviorInBulkEditForm attribute goes on the <event> element, careful you're not putting it somewhere else.
The valid values, as per Microsoft KB 949941, are:
Enabled
If you use this value, the field is enabled. Additionally, the code for the event is run when the event is called.
Disabled
If you use this value, the field is disabled.
EnabledButNoRender
If you use this value, the field is enabled. However, the code for the event is not run when the event is called.
I would recommend to stay away from unsupported customizations which will eventually break in future updates.
If it’s worth, then move all the logic to post-update or pre-update plugins which is fail proof server side implementation rather than client side js route.

How to know what InputParameters values are possible in Dynamics CRM Plugin context?

I'm trying to understand the plug-in sample from here.
There's this condition:
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
Speaking generally, not just with regard to this sample, on what prior knowledge should I base my decision to access a specific property? How could I have known to test whether the InputParameters contains a "Target" key (I assume I'm not supposed to guess it)?
And on what basis could I have known to ask whether the "Target" mapped value is of Entity type, and not some other type?
I found this post from 2 years ago, and I've found this webpage, saying (emphasis is mine):
Within a plugin, the values in context.InputParameters and
context.OutputParameters depend on the message and the stage that you
register the plugin on. For example, "Target" is present in
InputParameters for the Create and Update messages, but not the
SetState message. Also, OutputParameters only exist in a Post stage,
and not in a Pre stage. There is no single source of documentation
that provides the complete set of InputParameters and OutputParameters
by message and stage.
From my searchings, a single source still doesn't exist, but maybe the possible values can be found using the Dynamics Online platform, somewhere deep down the Settings menu, maybe? Any source would be great.
I know this is an "old" question that already has been answered, but I think this can be helpful. I've built a small web page that contains all the messages with all the Input/Output parameters. You can access it from here:
The best practice for doing this is to use a strongly typed approach. If, for example, you want to know which propertes are available on a CreateRequest, you would do:
var createReq = new CreateRequest() { Parameters = context.InputParameters };
createReq.Target; // Has type Entity
Take a look at the full blog post explaining this approach: Tip: Proper handling of Plugin InputParameters
Original answer:
It depends on which request we are talking about. See Understand the data context passed to a plug-in on MSDN.
As an example, take a look at CreateRequest. One property of
CreateRequest is named Target, which is of type Entity. This is the
entity currently being operated upon by the platform. To access the
data of the entity you would use the name “Target” as the key in the
input parameter collection. You also need to cast the returned
instance.
Note that not all requests contain a Target property that is of type
Entity, so you have to look at each request or response. For example,
DeleteRequest has a Target property, but its type is EntityReference.
In summary: Look at the actual request, e.g the CreateRequest.
In 2011 someone actually generated typed properties based on the message type. Kind of neat: https://xrmpalmer.wordpress.com/2013/05/27/crm2011-plugin-inputparameter-and-outputparameter-helper/
It would show you want parameters are possible per message.

Open phone call form with prefilled caller and direction using window.open

How could one open a phone call entity form so that direction is Incoming and that in "From" field there's a contact. I know already who is calling and I have the GUID. I know it's always contact. And I know that phone call is always incoming.
I have to use window.open function and pass those values in url. This site (https://msdn.microsoft.com/en-us/library/gg334375.aspx) does explain how to provide values for option sets and lookups, but in phone call "From" field is not a simple lookup but party list. And direction is not an option set but a Two options (if that makes any difference).
I have simply tried this
var extraqs = "directioncode=1&from=" + contactid;
window.open("https://myserver.crm4.dynamics.com/main.aspx?etn=phonecall&pagetype=entityrecord&extraqs=" + encodeURIComponent(extraqs));
but I can't get it work. I have tried to fiddle with those values back and forward and sometimes I get no error but it doesn't work either. Sometimes I get System.Web.HttpUnhandledException. I know it's probably because the format is off.
Another option I was thinkin that I could probably pass those values in url to the form and then create a function to form onLoad event where I could more easily set those field. But it sounds a workaround to me.
But my question is can I, and if how, set up those two fields?
A party list can not be set like a simple lookup.
Check out this blog post, it may guide you in setting party list
http://scaleablesolutions.com/open-new-activity-form-with-regarding-and-partylist-field-prefilled/

Creating dynamic web forms on the client side

Is there an existing library that would do this?
I want to be able to have code on the client side where the user chooses something, it makes a call to the server, and the server sends back "for this option, you need a have a text field called foo and a select field called bar with the following options, this one is selected, etc", and then the client side builds the next part of the form from that information. Or if they choose a different option, a different set of fields and values is returned from the server and populated on the screen. Also it might cascade so after the first selection we need a select field with some options, and then depending what they select on that select field the next field might be another select field or it might be a text input field.
Has anybody done anything like that? Is my best choice to have the AJAX call return some html that I just stuff into a div, or can I do it field by field and value by value?
If it matters, the back end is going to be written in Perl/MASON, and the front end will be using Javascript/JQuery/JQuery-UI.
I would use jquery and submit AJAX calls to whatever backend system you choose. Have this backend system compute the necessary changes and return the info as JSON. Let JQuery parse it for you and append the necessary form elements. However, it seems like under alot of use cases these decisions could be made on the client side without even talking to the server just as we pre validate form input before allowing posting to the server. I don't, however, have your requirements in front of me so I am sure there is a reason you want to get the info back from the server.
P.S. please do not return pure html from the back end to the client....ever.

CoreData prevent delete of defaults

I have an entity in my coredata document based application.
I have certain default values that get created when a new document is created for that entity.
I need to be able to allow users to add and remove from that list (easily done), but prevent users from deleting the default values (cant find the answer).
Thanks for your response, that is a good option in this case I think I will use it.
I was wondering though if anyone knows how a person can VALIDATE a delete.... so if a person clicks on the delete button, it will go through some logic (complex or simple, depending on the application) then either ignore the click or actually delete the object.
I've looked at the method validateForDelete: but there is very little documentation on it and i'm not sure if this is the intended use of the method.
You could add a boolean attribute to your entity that indicates whether or not a value is a default. You could then deactivate the delete button if the currently selected value is a default, using the enabled binding.

Resources