Showing posts with label Shortcuts. Show all posts
Showing posts with label Shortcuts. Show all posts

Friday, January 6, 2012

Read Form Id or Form XML of a specified entity form

CRM 2011 now allows multiple forms to be designed for an entity and based on the security roles display the appropriate form.

During the development we once came across the need to get the Formid for each of the forms created for an entity. We did not want to hard code the formid in the ribbon button as the id’s may change between test and production environments.

We can programmatically retrieve the FormId of an entity through Jscript.

The schema name for the entity that stores the information about the various forms is SystemForm. The code below retrieves the id for the specified form based on the form name.


function RetrieveGetFormIDRecord(formName)
{
var cols="";
try
{
var xml = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>"+
" <soapenv:Body>"+
" <RetrieveMultiple xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>"+
" <query i:type='a:QueryExpression' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>"+
" <a:ColumnSet>"+
" <a:AllColumns>false</a:AllColumns>"+
" <a:Columns xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>"+
" <b:string>formid</b:string>"+
" </a:Columns>"+
" </a:ColumnSet>"+
" <a:Criteria>"+
" <a:Conditions>"+
" <a:ConditionExpression>"+
" <a:AttributeName>name</a:AttributeName>"+
" <a:Operator>Equal</a:Operator>"+
" <a:Values xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>"+
" <b:anyType i:type='c:string' xmlns:c='http://www.w3.org/2001/XMLSchema'>"+formName+"</b:anyType>"+
" </a:Values>"+
" </a:ConditionExpression>"+
" </a:Conditions>"+
" <a:FilterOperator>And</a:FilterOperator>"+
" <a:Filters />"+
" </a:Criteria>"+
" <a:Distinct>false</a:Distinct>"+
" <a:EntityName>systemform</a:EntityName>"+
" <a:LinkEntities />"+
" <a:Orders />"+
" <a:PageInfo>"+
" <a:Count>0</a:Count>"+
" <a:PageNumber>0</a:PageNumber>"+
" <a:PagingCookie i:nil='true' />"+
" <a:ReturnTotalRecordCount>true</a:ReturnTotalRecordCount>"+
" </a:PageInfo>"+
" <a:NoLock>false</a:NoLock>"+
" </query>"+
" </RetrieveMultiple>"+
" </soapenv:Body>"+
"</soapenv:Envelope>";


// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", Xrm.Page.context.getServerUrl() + "/XRMServices/2011/organization.svc/web", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple");
xHReq.setRequestHeader("Content-type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);

// Capture the result.
var resultXml = xHReq.responseXML;

var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
return;
}

// Parse and display the results.
var results = resultXml.getElementsByTagName('a:Entity');
//if only one zip code records found
if (results.length != 0 )
{
//alert("Lenght: "+results.length);
var attribs = results[0].getElementsByTagName('a:Attributes/a:KeyValuePairOfstringanyType');
if (attribs.length == 0)
{
alert("No data found in enitty.");
return;
}

if(attribs[0].selectSingleNode('./b:key').nodeTypedValue =="formid" )
{
//set the field values
var value= attribs[0].selectSingleNode('./b:value').nodeTypedValue;
alert("FormID:"+value);
}
}

}//end of try
catch(e)
{
alert("RetrieveGetFormIDRecordErr: "+e.description);
}
}//end of RetrieveGetFormIDRecord

</Snip>

In the above code, we just need to pass the form name and it will return the form id. In the above query we can add the condition to filter by an entity like account forms as well by setting the “objecttypecode”.

Once you have the formid you can open the form using the following url

var accountPage= Xrm.Page.context.getServerUrl()+ "/main.aspx?etn=account&extraqs=formid%3D"+value+"%0D%0A&pagetype=entityrecord";
window.open(accountPage);






Monday, September 14, 2009

Add Shortcut button for new Activity on CRM toolbar

Some time back we had posted a script that would allow you to create an ISV button to bring up the new activity form (phone call, appointment etc).

Recently we had the same request from one of our customers and we were quick to offer them the same. Unfortunately it failed. The locAddActTo function is not available on main CRM form.

To get this done, we had to provide the following alternate script


<Button Icon="/_imgs/ico_16_4210_d.gif" JavaScript="window.open('/activities/phone/edit.aspx','null','height=500px,width=800px,resizable=1,status=yes,toolbar=no,menubar=no,location=no')"> <Titles> <Title LCID="1033" Text="New Phonecall" /> </Titles> <ToolTips> <ToolTip LCID="1033" Text="Create New Phonecall" /> </ToolTips>

</Button>

Sunday, June 7, 2009

Call Workflow from ISV button

We had once given an option to one of our customers to perform an action using on-demand workflow. We provided them with the steps to run the workflow from the "Run Workflow..." button that is added to the entity in case and entity has on-demand workflows published against them.

The customer however wanted that we add a button with a descriptive lable that performed the job so that the users are not burdened with having to select the correct workflow from the list and it was a one-click solution.

We found that CRM has an inbuilt function made available that calls the workflow "launchOnDemandWorkflow"

The syntax of the function is
launchOnDemandWorkflow('crmGrid',ObjectTypeCode,Workflow ID) //when called from grid

launchOnDemandWorkflow('',ObjectTypeCode,Workflow ID) //when called from entity form

This function has 3 parameters.
The first one is left blank only if the button is on the record of that entity and workflow needs to be called on that record only. whereas, if the button is placed on the grid of CRM entity view then first parameter should be 'crmGrid' so that the workflow will get called for the records selected in that view.


Second parameter contains object type code of that entity

Third parameter is the id of the workflow to be fired

To get the workflow id, follow the below steps.

1. Go to Setting --> Workflow form.
2. Here open the workflow that you want to run on button click.
3. Now press "Ctrl + N" which will open the same page in the IE.
4. In the Address bar of IE you can find the id of workflow.

This should help provide users with the most familiar option of clicking a button to perform an action.

Tuesday, February 24, 2009

Bulk Edit records of any entity in CRM

We can easily edit a record in crm. But what if we need to edit a field of all records with same value. So here, Instead of opening records one by one and editing it, we can also use Bulk edit feature which edits that field in one go for all records.

For some records like account,contact ,lead, Product etc, there is already an in-built feature for bulk editing these records.

Below we have explained how to bulk edit the account records :


  1. Select all the records for which you need to edit fields in bulk. We have selected all the account records as shown in the screen below:


2. Now go to More actions and click on edit.



3. Then you will get the window as shown in the screen below. Here, you can edit any field which will be applied to all the selected records. We have edited the account name.




4. Only when you save this form, you will find that all the selected records have been edited with that value. Here we edited account name and all the account names of selected records will be test as shown in the screen below :




This is how Bulk edit of account entity works.

Note :- CRM does not support bulk edit for all entities like Activities ,SalesOrder.

But, if you want to Bulk edit records of Activities ,salesorder which are not supported by CRM then we can do this also.

For this, you will have to write a JavaScript on “ISV Button” and place that button on the particular entity where bulk edit feature is desired.

In that script we have to call a function which is :

“doAction('crmGrid', 'entitytypecode', 'bulkedit')”

Below is a code for adding a button for bulk editing Appointment records which will be added in the isv.config :

//Start of Script

<Entity name="activitypointer">//You can change the entity name

<Grid>

<MenuBar>

<Buttons>

<Button Icon="/_imgs/ico_18_debug.gif" JavaScript="doAction('crmGrid', '4201', 'bulkedit');" Client="Web">

//”4201” is the entity type code of Appointment

<Titles>

<Title LCID="1033" Text="Bulk Edit" />

</Titles>

<ToolTips>

<ToolTip LCID="1033" Text="Bulk Edit." />

</ToolTips>

</Button>

</Buttons>

</MenuBar>

</Grid>

</Entity>

//End of Script


We have to only change the entitytypecode according to the entities required for bulk edit.

For example : If we want to bulk edit “Salesorder” then we have to write doAction function as follows:

“doAction('crmGrid', '1088', 'bulkedit')” where "1088" is the entitytypecode of salesorder entity.
We can also bulk edit the records for entities like phonecall,email etc by changing their respective entitytype codes in the doAction function.

Monday, February 16, 2009

Shortcut to open any record in CRM

There are a couple of generic urls that would let you open any type of record in CRM

  • If you need to open any type of record but don't know the URL. No worries just specify object type code (you can get object type code from CRM SDK under section" Entity Type Codes") and ID it will open your record. (Note that the parameter names are case sensitive here)

http://server:port/organization/CRMReports/viewer/drillopen.aspx?ID=objectid&OTC=objecttypecode

  • To open a record in ReadOnly mode

http://server:port/organization/_forms/readonly/readonly.aspx?objTypeCode=objecttypecode&id=objectid

You can call these from anywhere in CRM and it will identify the entity and open the relevant entity form. This does away the need or specifying url specific to the entity.

Shortcut to create activities for an account or contact

CRM Forms already have a button to quickly send an email. The "Follow up" button allows you to quickly create activities, however it does not show up the entire activity form.
If you instead wanted a way to create a task or some other activity and want the activity form to show-up without navigating to the Activities pane and click on New and select the appropriate entity, here is the code that will help


  • Send Email: locAddActTo(4202); // where 4202 = objecttypecode

  • Create Task: locAddActTo(4212)

The entire list of ObjectTypeCode for all entities in CRM can be found in the SDK

Friday, February 13, 2009

Shortcut to Add notes and attachments

You need to navigate to the Notes tab each time you need to add a note. Also the shortcut to add a quick note in CRM does not show up the note form that allows to fill in all details including subject and attachment in one go. If you want to add all information to the note it would involve atleast a couple or more of clicks to get all done.
You can add convenient shortcuts to add notes without having to navigate to the Notes tab and save a few clicks.


  • add a note : locAddObjTo(5); This will open up the new note form

  • attach a file : locAddFileTo(5); This will bring up the attach file form.

Shortcut to add new records for related entities

CRM navigation especially for adding related entities like activities/Contact/Quote Products etc is quite tedious and time consuming. You can add a shortcut for most of these on the main form and save quite a few clicks in the process.

First decide for which entity you need to add "Shortcut" button like if I need to create shortcut for "Existing Order Products" on order form.

So you need to create first URL. You can find URL by pressing CTRL+N on a form for which you need to create shortcut.


URL for adding existing order product:

/orgname/sfa/salesorderdetail/edit.aspx?_CreateFromType=&_CreateFromId=&locked=0

URL for adding write-in order product:

/orgname/sfa/salesorderdetail/edit.aspx?_CreateFromType=&_CreateFromId=&isproductoverridden=1

  • Every entity has an ObjectTypeCode associated with it. You can get the complete list in the SDK.

  • ObjectId above refers to the current entity id for which the child needs to be added.


You can add ISV button like shown in below on the Order entity,

<Button Icon="/_imgs/ico_18_1089.gif" JavaScript="window.open('/' + ORG_UNIQUE_NAME + '/sfa/salesorderdetail/edit.aspx?_CreateFromType=' + crmForm.ObjectTypeCode + '&amp;_CreateFromId=' + crmForm.ObjectId + '&amp;locked=0','my_ex_item_window','width=900,height=600,toolbar=no,status=yes,scrollbars=yes,resizable=yes')" PassParams="0" WinParams="" WinMode="0">

<Titles>

<Title LCID="1033" Text="Existing Item" />

</Titles>

<ToolTips>

<ToolTip LCID="1033" Text="Add existing order product" />

</ToolTips>

</Button>