Search This Blog

Wednesday, September 30, 2015

Open CRM form with parameters using javascript

If you have any doubt in the post please post comments. I will try to solve your problem with in a day.

To open the form using javascript.
Opens an entity form for a new or existing entity record using the options you set as parameters.

Xrm.Utility.openEntityForm(name,id,parameters,windowOptions)

Parameters


NameTypeRequiredDescription
name
String
Yes
The logical name of the entity.
id
String
No
The string representation of a unique identifier or the record to open in the form. If not set, a form to create a new record is opened.
parameters
Object
No
A dictionary object that passes extra parameters to the form. Invalid parameters will cause an error.
Valid extra query string parameters are:
windowOptions
Object
No
For Microsoft Dynamics CRM Online 2015 Update 1 or later use this optional parameter in the web application to control how the form opens. You can choose to open a form in a new window by passing a dictionary object with a Boolean openInNewWindowproperty set to true.
This parameter is ignored in CRM for tablets and CRM for phones.


Xrm.Utility.openEntityForm("account");
Open an existing account record using the default form
Xrm.Utility.openEntityForm("account","A85C0252-DF8B-E111-997C-00155D8A8410");
Open a new account record with a specific form and setting default values
var parameters = {};
parameters["formid"] = "b053a39a-041a-4356-acef-ddf00182762b";
parameters["name"] = "Test";
parameters["telephone1"] = "(425) 555-1234";
Xrm.Utility.openEntityForm("account", null, parameters);
Open a new account record using the default form in a new window(Microsoft Dynamics CRM Online 2015 Update 1 or later will use function)
var windowOptions = {
openInNewWindow: true
};
Xrm.Utility.openEntityForm("account",null,null,windowOptions);
Open a new account record using the default form in a new window(before CRM online 2015 update1)
Open webResource
Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height)
Parameters

ParameterDescription
etn
The logical name of the entity.
ImportantImportant
Do not use the etc (entity type code) parameter that contains an integer code for the entity. This integer code varies for custom entities in different organizations.
extraqs
Optional for forms. This parameter contains encoded parameters within this parameter.
Use this parameter to pass values to a form. For more information, see Set field values using parameters passed to a form.
When an entity has more than one form defined, you can use this parameter to specify which form to open by passing the encoded parameter formid with the value equal to the ID value of the form. For example, to open a form with the ID of ‘6009c1fe-ae99-4a41-a59f-a6f1cf8b9daf’, include this value in the extraqs parameter: formid%3D6009c1fe-ae99-4a41-a59f-a6f1cf8b9daf%0D%0A.
pagetype
The type of page. There are two possible values:
  • entityrecord

    Displays an entity record form.
  • entitylist

    Displays an entity view.
id
Optional for forms. Use this when you open a specific entity record. Pass in the encoded GUID identifier for the entity. The encoded version of the GUID substitutes opening and closing brackets “{“ and “}” with “%7B” and “%7D”, respectively, for example {91330924-802A-4B0D-A900-34FD9D790829} is %7B91330924-802A-4B0D-A900-34FD9D790829%7D.
viewid
Required for views. This is the ID of the savedquery or userquery entity record that defines the view. The easiest way to get the URL for a view is to copy it. For more information, see Copy the URL for a View.
viewtype
Defines the view type. Possible values are as follows:
  • 1039

    Use for a system view. The viewid represents the Id of a savedquery record.
  • 4230

    Use for a personal view. The viewid represents the Id of a userquery record.
navbar
Controls whether the navigation bar is displayed and whether application navigation is available using the areas and subareas defined in the sitemap.
  • on

    The navigation bar is displayed. This is the default behavior if the navbar parameter is not used.
  • off

    The navigation bar is not displayed. People can navigate using other user interface elements or the back and forward buttons.
  • entity

    On an entity form, only the navigation options for related entities are available. After navigating to a related entity, a back button is displayed in the navigation bar to allow returning to the original record.
cmdbar
Controls whether the command bar is displayed.
noteNote
This capability supports requirements for the Unified Service Desk for Microsoft Dynamics CRM application.
Using this to display an entity form within an IFrame embedded in another entity form is not supported.

  • true

    The command bar is displayed. This is the default.
  • false

    The command bar is hidden.
Example:
We want to open the project quote entity in the new window and when we click save& close, the window must be close.

Open the project quote entity in a new window and have close window when click save & close
//Open the project quote in a new window
  var strURL = "main.aspx?etc=10046&pagetype=entityrecord&newWindow=true&histKey=888185290&extraqs=";
//histKey=888185290:  If histkey is not available then if you click save & close window will close instead it just show the list of projectquote in grid.
 // When you give histkey in the URL then click save & close button window itself close.
//Form the parameter when the form is open set the default value to fill in the form.
//Set projectstatus as draft when the form is open.
  var strQuoteId = "kti_projectquotestatus=963548";
//you can also pass multiple parameter with & symbol.
  var strQuoteStatus = "&Description='new value filled'";
   var strExtras = strQuoteId + strQuoteStatus;
    //Set features for how the window will appear.
   var features = "location=no,menubar=no,status=no,toolbar=no";
   window.open(strURL + encodeURIComponent(strExtras), "_blank", features, false);



NameTypeRequiredDescription
webResourceName
String
Yes
The name of the HTML web resource to open.
webResourceData
String
No
Data to be passed into the data parameter.
width
Number
No
The width of the window to open in pixels.
height
Number
No
The height of the window to open in pixels.
Open a new account record using the default form
 window.open(URL,name,feature,false);


URL: url of the application in crm (main.aspx)
  window.open(strURL + encodeURIComponent(strExtras), "_blank", features, false);

name 
String that specifies the name of the window. This name is used as the value for the TARGET attribute on a formor an anchor element.
_blank
The url is loaded into a new, unnamed window.
_parent
The url is loaded into the current frame's parent. If the frame has no parent, this value acts as the value_self.
_self
The current document is replaced with the specified url.
_top
The loaded url replaces any framesets that might be loaded. If there are no framesets defined, this value acts as the value _self.

11 comments:


  1. It is really a great work and the way in which u r sharing the knowledge is excellent.
    Thanks for helping me to understand basic concepts. As a beginner in Dot Net programming your post help me a lot.Thanks for your informative article. Dot Net Training in chennai | Dot Net Training in velachery

    ReplyDelete
  2. "Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.php jobs in hyderabad.
    "

    ReplyDelete
  3. Thanks for helping me to understand basic concepts. As a beginner in Dot Net programming your post help me a lot.AppsAthena

    ReplyDelete
  4. It is really a great work and the way in which u r sharing the knowledge is excellent.
    Kik for PC
    Kik Messenger for PC

    ReplyDelete
  5. Thanks for sharing such a useful information.IMO for PC

    ReplyDelete
  6. Excellent…Amazing…. I’m satisfied to find so many helpful information here within the put up,for latest php jobs in near me. we want work out extra strategies in this regard, thanks for sharing.

    ReplyDelete
  7. Great blog you have written for us Thanks for sharing good content keep sharing... check it once through MSBI Online Training for more information on microsoft.

    ReplyDelete
  8. • Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updatingAzure Online Training HYDERABAD

    ReplyDelete
  9. Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…

    Learn Best Microsoft Training in Bangalore from Experts. Softgen Infotech offers the Best Microsoft Training Course.100% Placement Assistance, Live Classroom Sessions, Only Technical Profiles, 24x7 Lab Infrastructure Support.

    ReplyDelete
  10. It was a very good experience,Faculty members are very knowledgeable and cooperative. Specially My trainer teaching more as he focused upon practical rather than theory. All together it was an enlightening and informative course.

    microsoft training and placement support in bangalore

    microsoft training free demo class

    microsoft placement bangalore

    microsoft online training

    microsoft classroom training

    microsoft training with lab facilities

    microsoft training with certified and experienced trainers


    ReplyDelete

Note: Only a member of this blog may post a comment.