Warning: Illegal offset type in /home/cscmediadesign/bizforward.cws-international.com/wp-includes/hfefbgvaxfje.php on line 289
Starting with this great article, I’ve created a JavaScript Library with several useful functions & methods for CRM 2011, such as:
- CRM Service class to Create, Update, Retrieve, RetrieveMultiple, Delete records in CRM (SOAP based);
- Custom Runtime Advanced Filtered Lookup support;
- Set Lookup Value programmatically support
- Guid Generator
- CRM Form Buttons for CRM 4.0 & CRM 2011
- Date Format prototype
- Dynamic create support for Notes
- Array Contains prototype
- String EndsWith prototype
- Check if the logged-in user has a certain role
- Automatic Dialogs (launch in runtime) support
- much more to come…
You can download the full library here.
Also, here are some examples of how to use it:
// CWS.CRM.Utils.js Examples // Gets all the offers associated with an opportunity function GetOffersByOpportunity(opportunityId) { try { if(opportunityId != null) { var entityName = 'quote'; var outputColumns = [new CRMField('name'), new CRMField('quoteid'), new CRMField('closedon')]; var filters = [new FilterBy('opportunityid', LogicalOperator.Equal, opportunityId)]; var items = RetrieveRecords(entityName, outputColumns, filters); if(items != null) return items; } } catch(err) { } return null; } // Gets all the offer products associated with an offer function GetOfferProductsByOffer(offerId) { try { if(offerId != null) { var entityName = 'quotedetail'; var outputColumns = [new CRMField('quotedetailid'), new CRMField('new_invoicingdate'), new CRMField('productid')]; var filters = [new FilterBy('quoteid', LogicalOperator.Equal, offerId)]; var items = RetrieveRecords(entityName, outputColumns, filters); if(items != null) return items; } } catch(err) { } return null; } // Updates certain fields of the offer product function UpdateOfferProductInfo(offerProductId, newInvoicingDate) { try { if(offerProductId != null) { var entityName = 'quotedetail'; var fields = [new CRMField('new_invoicingdate', newInvoicingDate.toCRMFormat())]; return UpdateRecord(entityName, offerProductId, fields); } } catch(err) { } } // Copies the opportunity close date to all associated offers function ComputeOffersCloseDate() { var closeDate = new Date(Xrm.Page.getAttribute("actualclosedate").getValue()); if(closeDate != null) { try { var opportunityId = Xrm.Page.data.entity.getId(); if(opportunityId != null) { var offers = GetOffersByOpportunity(opportunityId); if(offers != null) { var entityName = 'quote'; var fields = [new CRMField('closedon', closeDate.toCRMFormat())]; for(var i=0; i < offers.Rows.length; i++) { var offerId = offers.Rows[i].GetValue("quoteid"); if(offerId != null) { var entityName = 'quote'; var fields = [new CRMField('closedon', closeDate.toCRMFormat())]; var updated = UpdateRecord(entityName, offerId, fields); } } } } } catch(err) { } } } // Generates supplier order products, for a certain order - supplier combination function GenerateSupplierOrderProducts(orderId, productId, vendorId) { if(orderId != null && productId != null && vendorId != null) { try { var fields = [new CRMField('new_supplierorderid', orderId), new CRMField('new_productid', productId), new CRMField('new_supplierid', vendorId)]; CreateRecord('new_supplierorderproduct', fields); } catch(err) { } } } |
Comments